Question

I have one table named tags and it contain entry which is as below.

 ID   Name       Created Date
 10 limit\'s 2013-06-27 05:18:35

Now i want to search for limit's using query but could not search record.

For what i have tried.

'SELECT id FROM tags AS Tag WHERE name = "%'. urlencode($adTag) .'%" LIMIT 0,1'

'SELECT id FROM tags AS Tag WHERE name LIKE "%'. htmlspecialchars($adTag) .'%" LIMIT 0,1'

'SELECT * FROM tags AS Tag WHERE name LIKE "%'. $adTag .'%" OR REPLACE(name,'''','') LIKE "%'. $adTag .'%"'

'SELECT id FROM tags AS Tag WHERE name LIKE "%'. mysql_real_escape_string( stripslashes($adTag)) .'%" LIMIT 0,1'

'SELECT id FROM tags AS Tag WHERE name LIKE "%'. mysql_real_escape_string($adTag) .'%" LIMIT 0,1'

Where $adTag is coming dynamically and its value is limit's. Above are tried but none of that worked.

Let me know what i am doing wrong so i can correct mysql.

Thanks.

Was it helpful?

Solution 2

Well after so many googleing work done i finally get this working.

below is the solution for me.

SELECT *
FROM tags
WHERE `name` = 'limit\\''s'
LIMIT 0 , 30

Its worked like charm. Hope this will help in future for other geeks.

OTHER TIPS

If you want to search for limit's, you have to have limit's in your table.
So, first of all get rid of the erroneous backslash in the table entry.

The rest is as usual

$tag = $db->getOne('SELECT id FROM tags WHERE name = ?s', $adTag);

I tried recreating your db and searching, it needs 2 addslashes to appear on the results. I think MySQL escapes the first slash automatically.

addslashes(addslashes($adTag));

Try this..

$sql = "SELECT id FROM tags AS Tag WHERE name LIKE %". mysql_real_escape_string( stripslashes(urldecode($adTag))) ."% LIMIT 0,1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top