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
https://forums.phpfreaks.com/topic/2512-small-error/
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
https://forums.phpfreaks.com/topic/2512-small-error/#findComment-8343
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
https://forums.phpfreaks.com/topic/2512-small-error/#findComment-8349
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
https://forums.phpfreaks.com/topic/2512-small-error/#findComment-8350
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
https://forums.phpfreaks.com/topic/2512-small-error/#findComment-8352
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
https://forums.phpfreaks.com/topic/2512-small-error/#findComment-8354
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
https://forums.phpfreaks.com/topic/2512-small-error/#findComment-8363
Share on other sites

Archived

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

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