xshanelarsonx Posted February 24, 2007 Share Posted February 24, 2007 I keep getting this error using this code. -String $Reason = "You don't live in B-Town"; -Function function autoban($date, $reason, $ip){ $autoban="INSERT into bans(ip,date,comment,active) VALUES('$ip','$date','$reason','1')"; mysql_query($autoban) or die(mysql_error()); echo ("<center><h1><font color='White'>You have been banned on the $date</font></h1></center>"); echo ("<center><font color='red'>Reason:</font> <font color='White'>$reason</font></center>"); exit(); } -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 't live in B-Town','1')' at line 1 Link to comment https://forums.phpfreaks.com/topic/39975-solved-mysql-problem/ Share on other sites More sharing options...
magic2goodil Posted February 25, 2007 Share Posted February 25, 2007 It is the ' in don't. Put a backslash before it and watch what happens. Link to comment https://forums.phpfreaks.com/topic/39975-solved-mysql-problem/#findComment-193297 Share on other sites More sharing options...
xshanelarsonx Posted February 25, 2007 Author Share Posted February 25, 2007 Thanks Magic2goodil, but how would I make it add the \ before any ' by its self? Link to comment https://forums.phpfreaks.com/topic/39975-solved-mysql-problem/#findComment-193299 Share on other sites More sharing options...
Jessica Posted February 25, 2007 Share Posted February 25, 2007 mysql_real_escape_string() Link to comment https://forums.phpfreaks.com/topic/39975-solved-mysql-problem/#findComment-193300 Share on other sites More sharing options...
magic2goodil Posted February 25, 2007 Share Posted February 25, 2007 Welcome. And yea, good call Jes. God I am lame, I am cleaning my room and talking on here, lol. Link to comment https://forums.phpfreaks.com/topic/39975-solved-mysql-problem/#findComment-193301 Share on other sites More sharing options...
xshanelarsonx Posted February 25, 2007 Author Share Posted February 25, 2007 Thanks Jesirose, can you give a example with my code? Link to comment https://forums.phpfreaks.com/topic/39975-solved-mysql-problem/#findComment-193303 Share on other sites More sharing options...
magic2goodil Posted February 25, 2007 Share Posted February 25, 2007 I think it's: mysql_real_escape_string($Reason,$db_connection); Link to comment https://forums.phpfreaks.com/topic/39975-solved-mysql-problem/#findComment-193309 Share on other sites More sharing options...
xshanelarsonx Posted February 25, 2007 Author Share Posted February 25, 2007 This don't work. What I'm trying to do is make it here my code will not give a error when reason has a ' in it. $autoban="INSERT into bans(ip,date,comment,active) VALUES('$ip','$date','$reason','1')"; mysql_query($autoban) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/39975-solved-mysql-problem/#findComment-193311 Share on other sites More sharing options...
Jessica Posted February 25, 2007 Share Posted February 25, 2007 look it up in the manual. Link to comment https://forums.phpfreaks.com/topic/39975-solved-mysql-problem/#findComment-193312 Share on other sites More sharing options...
xshanelarsonx Posted February 25, 2007 Author Share Posted February 25, 2007 Can someone please answer my question above. I can't figure it out. Link to comment https://forums.phpfreaks.com/topic/39975-solved-mysql-problem/#findComment-193328 Share on other sites More sharing options...
magic2goodil Posted February 25, 2007 Share Posted February 25, 2007 just do addslashes($variable); before you try and add it to database. Link to comment https://forums.phpfreaks.com/topic/39975-solved-mysql-problem/#findComment-193330 Share on other sites More sharing options...
superuser2 Posted February 25, 2007 Share Posted February 25, 2007 With mysql, you always mysql_real_escape_string any values you use. So: $reason = mysql_real_escape_string($reason); The db handle parameter is optional. Link to comment https://forums.phpfreaks.com/topic/39975-solved-mysql-problem/#findComment-193332 Share on other sites More sharing options...
xshanelarsonx Posted February 25, 2007 Author Share Posted February 25, 2007 Thanks everyone, its working now. Link to comment https://forums.phpfreaks.com/topic/39975-solved-mysql-problem/#findComment-193338 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.