1

i am able to enter text in html and am able to submit. but then i get a blank page. whats wrong? is it the code? here it is

<html>
<body>
<form action ="students.php" method="post">
USN : <input type="text" name="id">
NAME : <input type="text" name="n">
age : <input type="text" name="a">
<input type="submit">
</form>
</body>
</html>

and php code is 
<html>
<body>
<?php
$connect=mysqli_connect("localhost","root","1234") or die("cant connect");
mysqli_select_db($connect,"student") or die("cant connect to database");
$usn=$_POST["id"];
$name=$_POST["n"];
$age=$_POST["a"];
$query="insert into student_info (usn,name,age) values('$usn','$name','$age')";
if(mysqli_query($connect,$query))
{
echo "inserted";
}
else
{
echo "could not insert";
}
mysqli_close($connect);
?>
</body>
</html>
1
  • error_reporting(E_ALL); ini_set("display_errors", 1); Commented Nov 20, 2016 at 13:02

2 Answers 2

1

as stated in this answer :

https://stackoverflow.com/a/21429652/7091942.

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

However, this doesn't make PHP to show parse errors - the only way to show those errors is to modify your php.ini with this line:

display_errors = on
Sign up to request clarification or add additional context in comments.

Comments

0

You are validating incorrectly... You can use mysqli_affected_rows to check if there was a change in the database, instead of putting the query in an if statement, since that shouldn't work.

Also, consider using error_reporting(E_ALL); and look up sanitation, to secure your queries for sql-injection.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.