Rohlan Posted March 13, 2009 Share Posted March 13, 2009 Hi. This is my code, it queries the database to try and find the speficied email on my mysql table. $sql2="SELECT * FROM noticias WHERE id='1' AND lista_emails LIKE %".$rows['email']."%"; I get an error, saying: 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 '@com.com' at line 1 I guess I need to escape the @ symbol, how do I do this? Quote Link to comment https://forums.phpfreaks.com/topic/149261-solved-escaping-symbols-for-mysql-queries/ Share on other sites More sharing options...
Silverado_NL Posted March 13, 2009 Share Posted March 13, 2009 try enclosing the value with brackets. like this $sql2="SELECT * FROM noticias WHERE id='1' AND lista_emails LIKE '%".$rows['email']."%' "; instead of $sql2="SELECT * FROM noticias WHERE id='1' AND lista_emails LIKE %".$rows['email']."%"; Quote Link to comment https://forums.phpfreaks.com/topic/149261-solved-escaping-symbols-for-mysql-queries/#findComment-783812 Share on other sites More sharing options...
The Little Guy Posted March 13, 2009 Share Posted March 13, 2009 It wasn't working because you don't have quotes around your email. Also, you may want to use mysql_real_escape_string to secure your database. $email = mysql_real_escape_string($rows['email']); $sql2="SELECT * FROM noticias WHERE id='1' AND lista_emails LIKE '%$email%'"; Quote Link to comment https://forums.phpfreaks.com/topic/149261-solved-escaping-symbols-for-mysql-queries/#findComment-783815 Share on other sites More sharing options...
Rohlan Posted March 13, 2009 Author Share Posted March 13, 2009 Thanks Silverado_NL, that fixed it Thanks for you too The Little Guy, however this is just an internal script I need to run locally. Quote Link to comment https://forums.phpfreaks.com/topic/149261-solved-escaping-symbols-for-mysql-queries/#findComment-783823 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.