Ken Ken - 1 year ago 55
SQL Question

mysql INSERT INTO newbie help

I'm a newbie so bare with me. 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:



$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());

echo("Thank you for registering!")

It looks right to me.

Answer Source

don't you getting any syntax error?


echo("Thank you for registering!")

change to

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)