Thursday, April 25, 2019

mysql - Blank page after attempt to insert



Whenever I try to insert data into my database 'users' I always get a blank page. It doesn't give me any errors, it doesn't include 'mainmenu.php', or return any feedback what so ever. Can someone help me out? Here is the code:




include("mainmenu.php");


$con = mysql_connect("localhost", "root", "*********");
if (!$con) {
die('Connection failure.' . mysql_error());
}

//Variable def
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];

$usrname = $_POST['usrname'];
$password = $_POST['password'];

mysql_select_db("users",$con) or die(mysql_error());
mysql_query("INSERT INTO data (usrname, fname, lname, password, email) VALUES ($usrname, $fname, $lname, $password, $email)") or die(mysql_error());
mysql_close($con)

echo("Thank you for registering!")
?>



It looks right to me.


Answer



don't you getting any syntax error?



first



mysql_close($con)
echo("Thank you for registering!")



change to



mysql_close($con);
echo("Thank you for registering!");


second, please quote your $_POST and escape it properly
read this - Escaping single quote in PHP when inserting into MySQL)


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...