CodeIgniter Forums
Search with an apostrophe in mySQL - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Search with an apostrophe in mySQL (/showthread.php?tid=7228)



Search with an apostrophe in mySQL - El Forum - 03-30-2008

[eluser]mexor[/eluser]
When searching for something like "Ocean's 11" I get a database error:

Error Number: 1064

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 's 11%' ORDER BY title ASC' at line 1

SELECT * FROM addDVD WHERE title LIKE '%ocean's 11%' ORDER BY title ASC

How do I get around this?
Thanks!


Search with an apostrophe in mySQL - El Forum - 03-30-2008

[eluser]nirbhab[/eluser]
SELECT * FROM addDVD WHERE title LIKE '%ocean\’s 11%' ORDER BY title ASC

Code:
$search_it = "ocean’s";
$key = addslashes($search_it);
$sql = "SELECT * FROM addDVD WHERE title LIKE '%$key%' ORDER BY title ASC";



Search with an apostrophe in mySQL - El Forum - 03-31-2008

[eluser]mexor[/eluser]
works perfect, thanks! :-)