mysql - mysql_real_escape_string ISSUE -
if type
'
into search bar mysql error "sting" has not been escaped- think.
but reason why cant escape because dont think string.
the search box generates search results dynamically ajax type , finds results error:
    have error in sql syntax; check manual corresponds mysql server version right syntax use near '%' or location '%'%' or map '%'%' limit 0, 16' @ line 2   this mysql query:
<?php      if($_post['q']!=""){   include $_server['document_root'] . "/include/datebasecon.php";         $result = mysql_query("           select id, name, location,  map           accommodation name '%".$_post['q']."%' or location '%".$_post['q']."%' or map '%".$_post['q']."%' limit 0, 16")          or die(mysql_error());         $output = "";         while($row = mysql_fetch_array($result)){             $n = preg_replace("/(".$_post['q'].")/i","<span>$1</span>",$row['name']);             $l = preg_replace("/(".$_post['q'].")/i","<span>$1</span>",$row['location']);             $m = preg_replace("/(".$_post['q'].")/i","<span>$1</span>",$row['map']);             $output .= "<p>".$n." - ".$l."</p>";             }          print $output;      } ?>   is there anyway can fix after post query maybe?
when magic_quotes_gpc off (as should be!), $_post['q'] string ', 1 character. that's why it's appearing in sql code this:
%' or location '%'%' or map '%'%' limit 0, 16   the error takes place @ '%'%' because like string being prematurely terminated.
you can use mysql_real_escape_string() on $_post['q'] , it'll escaped:
$q = mysql_real_escape_string($_post['q']); $result = mysql_query("   select id, name, location,  map   accommodation name '%".$q."%' or location '%".$q."%' or map '%".$q."%' limit 0, 16")  or die(mysql_error());      
Comments
Post a Comment