Jump to content

Small Error


JamesRyzon

Recommended Posts

Ok ive been at this myself for some time

 

Im having an error inputting to a database, very simple error i assume but i cant seem to fix it (Even when i copy and paste a query from another page which i am POSITIVE works, ive even used phpmyadminl to generate code for me which worked but not inserting my variable)

 

$desc = " ".$mons." defeats ".$name." in defence";
$sql9 = mysql_query("INSERT INTO journal(desc) VALUES('$desc')")or die(mysql_error());

 

The table has two rows, ID which is set to auto_increment, and desc, which is set to text.

 

i get the following error 10/10 times -

 

u have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near...

 

after 'near' it shows the data that should be appended to $desc, and sent, but nothing is, sigh, any help?

Link to comment
Share on other sites

try this:

 

[!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--]$desc = mysql_escape_string(\" $mons defeats $name in defence\");

$sql9 = mysql_query(\"INSERT INTO journal(desc) VALUES(\'$desc\')\")or die(mysql_error());[/span][!--PHP-Foot--][/div][!--PHP-EFoot--]

Link to comment
Share on other sites

change:

 

$sql9 = mysql_query("INSERT INTO journal(desc) VALUES('$desc')")or die(mysql_error());

 

to

$sqlstring = "INSERT INTO journal(desc) VALUES('$desc')";
$sql9 = mysql_query($sqlstring)or die(mysql_error() . " in the query $sqlstring");

 

and post back your new error message.

 

Link to comment
Share on other sites

change:

 

$sql9 = mysql_query("INSERT INTO journal(desc) VALUES('$desc')")or die(mysql_error());

 

to

$sqlstring = "INSERT INTO journal(desc) VALUES('$desc')";
$sql9 = mysql_query($sqlstring)or die(mysql_error() . " in the query $sqlstring");

 

and post back your new error message.

295980[/snapback]

 

The entire error i got is this

 

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 'desc) VALUES(' DaRkNeSs defeats James3 in defence')' at line 1 in the query INSERT INTO journal(desc) VALUES(' DaRkNeSs defeats James3 in defence')

 

the code im using now

 

$desc = $mons.' defeats '.$name.' in defence';
$sqlstring = "INSERT INTO journal(desc) VALUES('$desc')";
$sql9 = mysql_query($sqlstring)or die(mysql_error() . " in the query $sqlstring");

Link to comment
Share on other sites

change:

$sqlstring = "INSERT INTO journal(desc) VALUES('$desc')";

 

to

$sqlstring = "INSERT INTO (`journal`,`desc`) VALUES('','$desc')";

295987[/snapback]

 

Recieving the same error pretty much

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 '(`journal`,`desc`) VALUES('',' DaRkNeSs defeats James3 in defen in the query INSERT INTO (`journal`,`desc`) VALUES('',' DaRkNeSs defeats James3 in defence')

Link to comment
Share on other sites

oops I made a mistake on my previous post. I have corrected it please try it again.

295990[/snapback]

 

Thank you that worked, is there any reason it was not auto_incrementing the ID on its own? Or is this something about SQL I was unaware of (When adding only one value, it messes up?)

 

Just trying to get some info on this so it dosent happen again.

 

Thanks again!

Link to comment
Share on other sites

Thank you that worked, is there any reason it was not auto_incrementing the ID on its own? Or is this something about SQL I was unaware of (When adding only one value, it messes up?)

 

Just trying to get some info on this so it dosent happen again.

 

Thanks again!

295991[/snapback]

The error was caused by the use of "desc" in your query. "desc" is a special keyword in MYSQL and if used as a column or table name should be surrounded by backticks(`) when referenced in a query as Czambran's example shows.

 

 

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.