Drezard Posted February 10, 2007 Share Posted February 10, 2007 Hello, I have got this error twice with 2 different queries... Here is the error: Error in query: INSERT INTO user_chars (user, char) VALUES ('Drezard', '0'). 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 'char) VALUES ('Drezard', '0')' at line 1 And here is the code that corresponds to it: $char = 0; $query = "INSERT INTO user_chars (user, char) VALUES ('$user', '$char')"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); the variable $user is set elsewhere and it definitly sets it (using echo i found that out). What else could be wrong? Cheers, Daniel Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 10, 2007 Share Posted February 10, 2007 Not sure what you are saying. You state that the variable $user is definitely set, but that doesn't have anything to do with the problem that I can see as ther is a value in the query for it. What data type are the columns user and char set as in the database? Is the value of $char (0) what you expect. Are the table and column names correct? Quote Link to comment Share on other sites More sharing options...
Drezard Posted February 10, 2007 Author Share Posted February 10, 2007 Doing a check now. 0 is what i want for char. Just telling you that user wasn't the problem. And the column are all varchars. What else could be wrong? - Cheers, Daniel Quote Link to comment Share on other sites More sharing options...
13th_Star Posted February 10, 2007 Share Posted February 10, 2007 its becuase your using the words char, which the mysql thinks that your trying to use e.g char(5) try this: INSERT INTO `user_chars` (`user`, `char`) VALUES ('Drezard', '0'). or if you dont wonna but the `` everytime you call to it just change the word char to something else. Quote Link to comment Share on other sites More sharing options...
Drezard Posted February 10, 2007 Author Share Posted February 10, 2007 Hello, These queries all before it work though... Except the last one: $query ="INSERT INTO user_ids (user, pass, priv) VALUES ('$user', '$pass', '$priv')"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); $query = "INSERT INTO user_profiles (user, email) VALUES ('$user', '$email')"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); $query = "INSERT INTO user_chars (user, char) VALUES ('$user', '$char')"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); Thats why i dont understand it... Quote Link to comment Share on other sites More sharing options...
paul2463 Posted February 10, 2007 Share Posted February 10, 2007 yes but all the other queries before do not include the word char - a reserved word in mysql if you wish to use the word char you have to tell mysql that you are using as a word and not as a command therefore as 13th_Star said you must but backticks around that word`char` this tells mysql/PHP that is is a string not a command. and another good idea is to change the names of your queries and results sets so when the error gets thrown you know where the error is <?php $query = "blah"; $result = mysql_query($query) or die "Error in query $query". mysql_error()); $query1 = "blah"; $result1 = mysql_query($query1) or die "Error in query $query1". mysql_error()); etc etc ?> Quote Link to comment Share on other sites More sharing options...
Drezard Posted February 10, 2007 Author Share Posted February 10, 2007 Swaping Char to the word Character.... Gives me this error: Error in query: INSERT INTO user_chars (user, 'character') VALUES ('Drezard3', '0'). 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 ''character') VALUES ('Drezard3', '0')' at line 1 For this bit of code: $character = 0; $query ="INSERT INTO user_ids (user, pass, priv) VALUES ('$user', '$pass', '$priv')"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); $query = "INSERT INTO user_profiles (user, email) VALUES ('$user', '$email')"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); $query = "INSERT INTO user_chars (user, 'character') VALUES ('$user', '$character')"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); What else could it be? - Cheers, Daniel Quote Link to comment Share on other sites More sharing options...
paul2463 Posted February 10, 2007 Share Posted February 10, 2007 Swaping Char to the word Character.... Gives me this error: Error in query: INSERT INTO user_chars (user, 'character') VALUES ('Drezard3', '0'). 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 ''character') VALUES ('Drezard3', '0')' at line 1 For this bit of code: $character = 0; $query ="INSERT INTO user_ids (user, pass, priv) VALUES ('$user', '$pass', '$priv')"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); $query = "INSERT INTO user_profiles (user, email) VALUES ('$user', '$email')"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); $query = "INSERT INTO user_chars (user, 'character') VALUES ('$user', '$character')"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); What else could it be? - Cheers, Daniel yes the proplem now is that you have single ticks around the word character they should be backticks `` not single ticks '' - big difference to mysql try this one $query = "INSERT INTO user_chars (user, `character`) VALUES ('$user', '$character')"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); 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.