newb Posted August 10, 2006 Share Posted August 10, 2006 [code=php:0]$sql = "INSERT INTO $table_users VALUES('$userid', $first_name', '$last_name', '$email_address', '$username', '$mdpwd', '$today')";if ($name == "reg") {$query = mysql_query( $sql ) or die(mysql_error());} else {[/code]i get this error:[quote]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VALUES('0', dfg', 'fdg', 'gfdg', 'gfd', '6289f8aefb7e446ab0a0f10d027e6c68', 'Aug' at line 1[/quote] Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 10, 2006 Share Posted August 10, 2006 You are missing one of your single quotes...the one first one on $first_name.[code]$sql = "INSERT INTO $table_users VALUES('$userid', --> ' <-- $first_name', '$last_name', '$email_address', '$username', '$mdpwd', '$today')";[/code] Quote Link to comment Share on other sites More sharing options...
rab Posted August 10, 2006 Share Posted August 10, 2006 [quote author=newb link=topic=103656.msg412892#msg412892 date=1155174520][code=php:0]$sql = "INSERT INTO $table_users VALUES('$userid', $first_name', '$last_name', '$email_address', '$username', '$mdpwd', '$today')";if ($name == "reg") {$query = mysql_query( $sql ) or die(mysql_error());} else {[/code]i get this error:[quote]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VALUES('0', dfg', 'fdg', 'gfdg', 'gfd', '6289f8aefb7e446ab0a0f10d027e6c68', 'Aug' at line 1[/quote][/quote]You missed a quote, read your error next time. [code=php:0]INSERT INTO $table_users VALUES('$userid', $first_name',[/code] Quote Link to comment Share on other sites More sharing options...
newb Posted August 10, 2006 Author Share Posted August 10, 2006 ok i changed the query now to [code=php:0]$sql = mysql_query("INSERT INTO $table_users VALUES('$userid', $first_name', '$last_name', '$email_address', '$username', '$mdpwd', '$today')");[/code]but now i get this error:[quote]Query was empty[/quote]whats that mean :s Quote Link to comment Share on other sites More sharing options...
corbin Posted August 10, 2006 Share Posted August 10, 2006 Means it didnt return any rows... AKA its empty Quote Link to comment Share on other sites More sharing options...
king arthur Posted August 10, 2006 Share Posted August 10, 2006 Change it to this and let's see what the query string actually is.[code]$query = "INSERT INTO $table_users VALUES('$userid', $first_name', '$last_name', '$email_address', '$username', '$mdpwd', '$today')";echo $query;$sql = mysql_query($query);[/code] Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 10, 2006 Share Posted August 10, 2006 You all are still missing the single quote before $first_name. Quote Link to comment Share on other sites More sharing options...
newb Posted August 10, 2006 Author Share Posted August 10, 2006 hmm didnt echo anything Quote Link to comment Share on other sites More sharing options...
newb Posted August 10, 2006 Author Share Posted August 10, 2006 k the code is this:[code=php:0]$query = mysql_query("INSERT INTO $table_users VALUES('$userid', '$first_name', '$last_name', '$email_address', '$username', '$mdpwd', '$today')");if ($name == "reg") {echo $query;$sql = mysql_query($query) or die(mysql_error());} else {[/code]all it did was give me[quote]Query was empty[/quote] Quote Link to comment Share on other sites More sharing options...
king arthur Posted August 10, 2006 Share Posted August 10, 2006 No, no, no......the first line should just be[code]$query = "INSERT INTO $table_users VALUES('$userid', $first_name', '$last_name', '$email_address', '$username', '$mdpwd', '$today')";[/code] Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 10, 2006 Share Posted August 10, 2006 http://www.tizag.com/mysqlTutorial/mysqlinsert.phpAny reason why you don't specify what fields you want the data inserted into? Quote Link to comment Share on other sites More sharing options...
newb Posted August 10, 2006 Author Share Posted August 10, 2006 why should i. Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 10, 2006 Share Posted August 10, 2006 [quote author=newb link=topic=103656.msg412915#msg412915 date=1155176028]why should i.[/quote]Good practice maybe. What are you going to do when you want to add a new field to your database table? Go back and edit every instance of the insert query so you get the right data in the right place? Quote Link to comment Share on other sites More sharing options...
newb Posted August 10, 2006 Author Share Posted August 10, 2006 [code=php:0]$query = mysql_query("INSERT INTO $table_users (id, first_name, last_name, email_address, username, password, signup_date) VALUES('$userid', '$first_name', '$last_name', '$email_address', '$username', '$mdpwd', '$today')");[/code]didnt help, still getting same error. Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 10, 2006 Share Posted August 10, 2006 Make a useful modification to your code so that you can see what's happening. Report ALL the output you get.[code]$query = "INSERT INTO $table_users (id, first_name, last_name, email_address, username, password, signup_date) VALUES('$userid', '$first_name', '$last_name', '$email_address', '$username', '$mdpwd', '$today')";$result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);[/code] Quote Link to comment Share on other sites More sharing options...
newb Posted August 10, 2006 Author Share Posted August 10, 2006 now i get this error msg with ur modifcation:[quote]Error: Query was empty with query[/quote] Quote Link to comment Share on other sites More sharing options...
king arthur Posted August 10, 2006 Share Posted August 10, 2006 Can you put the "echo $query" in so we can see what the string is that you are actually passing to mysql_query()? Quote Link to comment Share on other sites More sharing options...
newb Posted August 10, 2006 Author Share Posted August 10, 2006 i did, and it didnt echo anythingheres my code:[code=php:0]$query = mysql_query("INSERT INTO $table_users (id, first_name, last_name, email_address, username, password, signup_date) VALUES('$userid', '$first_name', '$last_name', '$email_address', '$username', '$mdpwd', '$today')");echo $query;$sql = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);[/code] Quote Link to comment Share on other sites More sharing options...
king arthur Posted August 10, 2006 Share Posted August 10, 2006 Ok....Look closely. Change your code to this. Exactly this. Do not add anything, do not take anything away.[code]$query = "INSERT INTO $table_users (id, first_name, last_name, email_address, username, password, signup_date) VALUES('$userid', '$first_name', '$last_name', '$email_address', '$username', '$mdpwd', '$today')";echo $query;$sql = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);[/code]And now let's see what the actual query string is. Quote Link to comment Share on other sites More sharing options...
newb Posted August 10, 2006 Author Share Posted August 10, 2006 now i get this error message:[quote]INSERT INTO (id, first_name, last_name, email_address, username, password, signup_date) VALUES('0', 'fgfgf', 'gfdg', 'gfdg', 'gfdg', '4e9ebbae28f66d96998f49edc51ebcde', 'August 9, 2006, 9:58 pm')Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(id, first_name, last_name, email_address, username, password, signup_date) VALU' at line 1 with query INSERT INTO (id, first_name, last_name, email_address, username, password, signup_date) VALUES('0', 'fgfgf', 'gfdg', 'gfdg', 'gfdg', '4e9ebbae28f66d96998f49edc51ebcde', 'August 9, 2006, 9:58 pm')[/quote] Quote Link to comment Share on other sites More sharing options...
king arthur Posted August 10, 2006 Share Posted August 10, 2006 Username and password are reserved words. Put backticks around them if you must use those column names.[code]$query = "INSERT INTO $table_users (id, first_name, last_name, email_address, `username`, `password`, signup_date) VALUES('$userid', '$first_name', '$last_name', '$email_address', '$username', '$mdpwd', '$today')";echo $query;$sql = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);[/code] Quote Link to comment Share on other sites More sharing options...
newb Posted August 10, 2006 Author Share Posted August 10, 2006 didnt help, same error i believe.[quote]INSERT INTO (id, first_name, last_name, email_address, `username`, `password`, signup_date) VALUES('0', 'fgfgf', 'gfdg', 'gfdg', 'gfdg', 'c43f0cf37469a3f1b20342132b0451de', 'August 9, 2006, 10:02 pm')Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(id, first_name, last_name, email_address, `username`, `password`, signup_date) ' at line 1 with query INSERT INTO (id, first_name, last_name, email_address, `username`, `password`, signup_date) VALUES('0', 'fgfgf', 'gfdg', 'gfdg', 'gfdg', 'c43f0cf37469a3f1b20342132b0451de', 'August 9, 2006, 10:02 pm')[/quote] Quote Link to comment Share on other sites More sharing options...
king arthur Posted August 10, 2006 Share Posted August 10, 2006 These are definitely the correct column names? Quote Link to comment Share on other sites More sharing options...
newb Posted August 10, 2006 Author Share Posted August 10, 2006 yeah they are. Quote Link to comment Share on other sites More sharing options...
newb Posted August 10, 2006 Author Share Posted August 10, 2006 just to be sure, just ran the query in phpMyAdmin, and it executed properly...so its definitely something with php :sphpMyAdmin returned this:[quote]Inserted rows: 1Inserted row id: 1 (Query took 0.0003 sec)SQL query: INSERT INTO p16_users( id, first_name, last_name, email_address, `username` , `password` , signup_date )VALUES ('$userid', '$first_name', '$last_name', '$email_address', '$username', '$mdpwd', '$today')[/quote] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.