Hi guys I am relatively new to php / sql so please forgive me for being stupid. I am trying to insert data into a database table but every time i check phpMyAdmin it doesnt seem to have worked. The code is as follows: $dbname= 'database1'; $dbcnx = mysql_connect('111.111.111.111', 'username', 'password'); or die("Connection Failure to Database"); mysql_select_db($dbname, $dbcnx) or die ($dbname . " Database not found. "); $sql ="INSERT INTO `test` ( `id` , `name` , `answer1` ) VALUES ( NULL , $user , $q1);"; mysql_db_query($dbname, $sql) or die("Failed Query of " . $sql); Is that enough code to do the job or do i need some more? Your help would be greatly appreciated! Cheers in advance.
Try putting single quotes round non-numeric values, i.e. change your query to: $sql ="INSERT INTO `test` ( `id` , `name` , `answer1` ) VALUES ( NULL , '$user' , '$q1');"; PHP:
I think you could do it with less code... $dbname= 'database1'; $dbcnx = mysql_connect('111.111.111.111', 'username', 'password'); or die("Connection Failure to Database"); mysql_select_db($dbname) or die ($dbname . " Database not found. "); $sql ="INSERT INTO `test` ( `id` , `name` , `answer1` ) VALUES ('', '$user' , '$q1');"; mysql_query($sql) or die("Failed Query of " . $sql); PHP: