MySQL Error

YamiKaitou

Member
Messages
636
Reaction score
0
Points
16
How can I fix this error?

Error: 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 ' `Reinstallation of database`)' at line 1

Code dealing with that line:
Code:
		$reason = "\'Reinstallation of database\'";
		$log = "INSERT INTO `develop_log` (`Num`, `User`, `Action`) VALUES (NULL, $id, $reason);";
		mysql_query($log) or die (mysql_error());
&id is defined elsewhere
 

Micro

Retired staff <i> (11-12-2008)</I>
Messages
1,301
Reaction score
0
Points
36
put $id and $reason into {} -- eg {$id} {$reason}
 

dest581

New Member
Messages
348
Reaction score
0
Points
0
Alternatively, though it wouldn't look as nice, you could make them look like ".$reason."
 

Micro

Retired staff <i> (11-12-2008)</I>
Messages
1,301
Reaction score
0
Points
36
Although, if you use {$reason} it prevents problems with quotes later on. You can fully make an error message in html this way and then put {$reason} in the html (Or from external files) and get it to parse it.
 

YamiKaitou

Member
Messages
636
Reaction score
0
Points
16
Micro, do you mean like this?
Code:
		$reason = "\'Reinstallation of database\'";
		$log = "INSERT INTO `develop_log` (`Num`, `User`, `Action`) VALUES (NULL, {$id}, {$reason});";
		mysql_query($log) or die (mysql_error());

Because I still get the same error. Could you explain how I should write the code if you mean differently?
 

Micro

Retired staff <i> (11-12-2008)</I>
Messages
1,301
Reaction score
0
Points
36
Um, dont you have to quote round strings? If im not mistaken i think you might have to. Bit rusty with MySQL, gotta learn it a bit more and get some decent stuff coded.

Also, you dont have to escape quotes in $reason if you have "" round it and use '.
 
Last edited:

Brandon

Former Senior Account Rep
Community Support
Messages
19,181
Reaction score
28
Points
48
Try this

Code:
$reason = "\'Reinstallation of database\'";
$log = "INSERT INTO `develop_log` (`Num`, `User`, `Action`) VALUES (NULL, {$id}, {$reason})";
mysql_query($log) or die (mysql_error());

You had an extra ";"
 
Last edited:

YamiKaitou

Member
Messages
636
Reaction score
0
Points
16
Nope, that didn't work either. But, I did get it to work, here is the code
Code:
$reason = "Reinstallation of database";
$log = 'INSERT INTO `develop_log` (`Num`, `User`, `Action`) VALUES (NULL, \'$id\', \'$reason\')';
mysql_query($log) or die (mysql_error());
 

Brandon

Former Senior Account Rep
Community Support
Messages
19,181
Reaction score
28
Points
48
Thatll work, use
Code:
'
instead of
Code:
"
.
 
Top