Jump to content

Escaping characters causing problems in queries


CodeMama

Recommended Posts

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?

ugh sorry took to long  :wtf:

 

<?php
//dissallowing  certain characters
$pattern[0]="#";
$pattern[1]="(";
$pattern[2]=")";
$replacement[0]="";
$replacement[1]="";
$replacement[2]="";
preg_replace($pattern,$replacement,$string);
?>

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.

   <?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&nbsp',$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>';
                                                              }
                                                                }
                                                           
                                                             
                                                                
                                                    
                                                      
                                  
                                                      ?>

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&nbsp', $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>';
      }
  }
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.