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>
Madhawa Priyashantha
  • 9,208
  • 7
  • 28
  • 58

2 Answers2

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
Community
  • 1
  • 1
Michael Yousrie
  • 964
  • 1
  • 8
  • 19
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.