Jump to content

Archived

This topic is now archived and is closed to further replies.

JamesRyzon

Small Error

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?

Share this post


Link to post
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--]

Share this post


Link to post
Share on other sites

Tried even copy and pasting it as you have and i still recieve the same error. Ive also tried switching types to compensate and no luck.

Share this post


Link to post
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.

 

Share this post


Link to post
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");

Share this post


Link to post
Share on other sites

change:

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

 

to

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

Share this post


Link to post
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')

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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!

Share this post


Link to post
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.

 

 

Share this post


Link to post
Share on other sites

×

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.