CodeMama Posted July 17, 2009 Share Posted July 17, 2009 I just noticed that any restaurant with a &, () or # in the name like say for example Arby's Store #12 ...will not return results... Yet if a name has a / or a - it's not a problem... 1. why is this and how do and where do I escape those characters on the query? Or on the insert? do I use ltrim and where? on the select? Link to comment https://forums.phpfreaks.com/topic/166337-escaping-characters-causing-problems-in-queries/ Share on other sites More sharing options...
darkfreaks Posted July 17, 2009 Share Posted July 17, 2009 might use the ctype_alnum function and is_numeric and ctype_punct Link to comment https://forums.phpfreaks.com/topic/166337-escaping-characters-causing-problems-in-queries/#findComment-877143 Share on other sites More sharing options...
darkfreaks Posted July 17, 2009 Share Posted July 17, 2009 for example: <?php //dissallowing certain characters $pattern[0]="#"; $pattern[1]="("; $pattern[2]=")"; $replacement[0]=""; $replacement[1]=""; $replacement[2]=""; preg_replace( ?> Link to comment https://forums.phpfreaks.com/topic/166337-escaping-characters-causing-problems-in-queries/#findComment-877154 Share on other sites More sharing options...
darkfreaks Posted July 17, 2009 Share Posted July 17, 2009 ugh sorry took to long <?php //dissallowing certain characters $pattern[0]="#"; $pattern[1]="("; $pattern[2]=")"; $replacement[0]=""; $replacement[1]=""; $replacement[2]=""; preg_replace($pattern,$replacement,$string); ?> Link to comment https://forums.phpfreaks.com/topic/166337-escaping-characters-causing-problems-in-queries/#findComment-877160 Share on other sites More sharing options...
CodeMama Posted July 17, 2009 Author Share Posted July 17, 2009 thanks for the suggestions, I just noticed an odd thing...it seems to only hang on some of the names... I just clicked one that had name store #() and it passed thru and showed the results, yet on others that have either a # or ( ) it will give me no results.... I think empty spaces are affecting it too...argh. Link to comment https://forums.phpfreaks.com/topic/166337-escaping-characters-causing-problems-in-queries/#findComment-877186 Share on other sites More sharing options...
darkfreaks Posted July 17, 2009 Share Posted July 17, 2009 can you paste the code please? Link to comment https://forums.phpfreaks.com/topic/166337-escaping-characters-causing-problems-in-queries/#findComment-877213 Share on other sites More sharing options...
CodeMama Posted July 17, 2009 Author Share Posted July 17, 2009 <?php //alphabetical pagination links $letter = isset($_GET['letter']) ? $_GET['letter'] :"A"; echo '<div align="center"><b>'; foreach(range('A','Z') as $c){ ($letter == $c) ? printf('%s ',$c) : printf('<a href="browse.php?letter=%s">%s</a> ',$c,$c); } echo "</b></div><p>"; if (!empty($_GET['name'])) { $name = $_GET['name']; $sql = "SELECT name, address, inDate, inType, notes, critical, cviolations, noncritical FROM restaurants WHERE name LIKE '$name'"; $result = mysql_query($sql) or die(mysql_error()); $header = false; while($row = mysql_fetch_assoc($result)){ if(!$header){ echo '<b>',($row['name']),'</b><br>'; echo '<b>',($row['address']),'</b><br><hr>'; $header = true; } echo 'Inspection Date:', ($row['inDate']),'<br>'; echo 'Inspection Type:',($row['inType']),'<br>'; echo 'Notes:', ($row['notes']),'<br>'; echo 'Critical Violations:',($row['critical']),'<br>' ; echo ($row['cviolations']),'<hr>'; } } ?> Link to comment https://forums.phpfreaks.com/topic/166337-escaping-characters-causing-problems-in-queries/#findComment-877266 Share on other sites More sharing options...
darkfreaks Posted July 17, 2009 Share Posted July 17, 2009 Try: <?php //alphabetical pagination links $letter = isset($_GET['letter']) ? $_GET['letter'] : "A"; echo '<div align="center"><b>'; foreach (range('A', 'Z') as $c) { ($letter == $c) ? printf('%s ', $c) : printf('<a href="browse.php?letter=%s">%s</a> ', $c, $c); } echo "</b></div><p>"; if (!empty($_GET['name']) && isset($_GET['name'])) { $name = trim($_GET['name']); $sql = "SELECT name, address, inDate, inType, notes, critical, cviolations, noncritical FROM restaurants WHERE name LIKE '$name'"; $result = mysql_query($sql) or die(mysql_error()); $header = false; while ($row = mysql_fetch_assoc($result)) { if (!$header) { echo '<b>', ($row['name']), '</b><br>'; echo '<b>', ($row['address']), '</b><br><hr>'; $header = true; } echo 'Inspection Date:', ($row['inDate']), '<br>'; echo 'Inspection Type:', ($row['inType']), '<br>'; echo 'Notes:', ($row['notes']), '<br>'; echo 'Critical Violations:', ($row['critical']), '<br>'; echo($row['cviolations']), '<hr>'; } } ?> Link to comment https://forums.phpfreaks.com/topic/166337-escaping-characters-causing-problems-in-queries/#findComment-877331 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.