siric Posted May 18, 2010 Share Posted May 18, 2010 Hi, I am doing a search on a table with a string that will be submitted by a user and want to prevent sql injection and am using mysql_real_escape_string. The thing is that my search is a wildcard search $search = mysql_real_escape_string($contains); $search = "%".$search."%"; If attempts an injection, the $search string equates to '%%', when then returns results for the entire table. Even if I add if ($calysponiansearch == '%%') { $calypsoniansearch = "%a"; } that does not work as the escaped characters are there but not displayed. How can I prevent this? Thanks Steve Quote Link to comment Share on other sites More sharing options...
Mchl Posted May 18, 2010 Share Posted May 18, 2010 That has nothing to do with injection. Unless passing an empty string can be considered an injection... $search = mysql_real_escape_string($contains); if(!empty($search)) { $search = "%$search%"; } Quote Link to comment Share on other sites More sharing options...
siric Posted May 18, 2010 Author Share Posted May 18, 2010 That has nothing to do with injection. Unless passing an empty string can be considered an injection... If I pass "" OR 1 in the $contains variable, I end up with $searchstring being equal to %% which then displays everything in the table. Quote Link to comment Share on other sites More sharing options...
Mchl Posted May 18, 2010 Share Posted May 18, 2010 If I pass "" OR 1 in the $contains variable, I end up with $searchstring being equal to %% which then displays everything in the table. Did you ever check it? mysql_connect('localhost','root',''); $contains = '"" OR 1'; $search = mysql_real_escape_string($contains); $search = "%".$search."%"; echo $search; %\"\" OR 1% Quote Link to comment Share on other sites More sharing options...
siric Posted May 18, 2010 Author Share Posted May 18, 2010 Hi, Problem was a misspelling on the variable that I assigned when I did the mysql_real_escape_strring :-\ Working too late at night!! Thanks for the help. Quote Link to comment Share on other sites More sharing options...
Mchl Posted May 18, 2010 Share Posted May 18, 2010 Happens. That's why E_NOTICE error level is so useful 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.