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 Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 25, 2007 Share Posted February 25, 2007 mysql_real_escape_string() Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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); Quote Link to comment 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()); Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 25, 2007 Share Posted February 25, 2007 look it up in the manual. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
xshanelarsonx Posted February 25, 2007 Author Share Posted February 25, 2007 Thanks everyone, its working now. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.