Jump to content

MySQL - 0 Error


Drezard

Recommended Posts

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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...

 

Link to comment
Share on other sites

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
?>

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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());

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.