Ken Ken - 4 months ago 7
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:

<?php

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)

Comments