What's wrong with my PHP/MySql code?

Ryuzo

New member
I have a PHP page as a HTML form back-end. The HTML form sends data to the PHP page via POST method and I want the PHP page to store data to a MySql database.

I tried the following codes but neither seems to actually update the dbase. The database has no password set.

(1) Storing the data to PHP variables and using the variables in the query-

$conn = mysql_connect($dbhost, $dbuser) or die('Error.');
$q_insertdb = "INSERT INTO details (`index` ,`username` ,`password` ,`firstname` ,`lastname` ,`gender` ,`dateofbirth` ,`age` ,`country` ,`city` ,`address` ,`phone` ,`qualification` ,`coursename` )VALUES (NULL , `".$username."` , `".$password."` , `".$firstname."` , `".$lastname."` , `".$gender."` , `".$dateofbirth."` , `".$age."` , `".$country."` , `".$city."` , `".$address."` , `".$phone."` , `".$qualification."` , `".$course."` );";
mysql_select_db('dbase1');
$success = mysql_query($q_insertdb);
echo $success;
mysql_close($conn);

(2) Sending it directly-

$conn = mysql_connect($dbhost, $dbuser) or die('Error.');
$q_insertdb = "INSERT INTO details (`index` ,`username` ,`password` ,`firstname` ,`lastname` ,`gender` ,`dateofbirth` ,`age` ,`country` ,`city` ,`address` ,`phone` ,`qualification` ,`coursename` )VALUES (NULL , `".$_POST['username']."` , `".$_POST['password']."` , `".$_POST['firstname']."` , `".$_POST['lastname']."` , `".$_POST['gender']."` , `".$dateofbirth."` , `".$age."` , `".$_POST['country']."` , `".$_POST['city']."` , `".$_POST['address']."` , `".$_POST['phone']."` , `".$_POST['qualification']."` , `".$_POST['course']."` );";
mysql_select_db('dbase1');
$success = mysql_query($q_insertdb);
echo $success;
mysql_close($conn);

$success variable does not return 0 or 1. And database is not updated. The database exists and is valid but the query doesn't work for some reason. Can anyone tell me why this is not working?
 
Back
Top