php - How to disable % from outputting everything -


hey have search field searching database, saw problem after testing if put "%" in search field output have ready searching. there way disable this?

<h3>search share details</h3> <p>you may search either company name or issue date</p>  <form name = "search" method = "get"> <input type = "text" name = "share" size = "40" maxlength="50"> <input type = "submit" value = "search"> </form> 

getting contents connecting db, fetching results , printing

function get_contents() {     if(isset($_get['share']))     {         $conn = db_connect();         $shares = get_sharesearch($conn);         db_disconnect($conn);         $contents = array('shares' => $shares);         return $contents;     }     else     {         $conn = db_connect();         $shares = get_share($conn);         db_disconnect($conn);         $contents = array('shares' => $shares);         return $contents;     } }   function print_contents($contents)  {      if(count($contents['shares']) == 0)     {         echo "<script type = 'text/javascript'>alert('sorry share not found! q_q');</script>";      }     else     {     ?>            <table>             <tr>                 <th>company name</th>                 <th>rate</th>                 <th>issue date</th>              </tr>     <?php     foreach ($contents['shares'] $share)      {         print "<tr>";         $identifier = urlencode($share['shareid']);         print "<td><a href='share-details.php?id={$identifier}'>{$share['company']}</a></td>";         print "<td>{$share['rate']}</td>";          $issue_date = $share['issue_date'];         $issue_date = $issue_date === null ? "&lt; not available &gt;" : $issue_date;         print "<td>{$issue_date}</td>";         print "</tr>";     }     ?>         </table>     <?php     } } //require("shares.php"); require("search.php"); ?> 

query itself

function get_sharesearch($conn) {  $id = ""; if(isset($_get['share'])){$id = $_get['share'];} $statement = db_create_statement($conn, "select distinct * shares  where(company '{$id}' or issue_date '{$id}')"); $resultset = db_fetch_resultset($statement);  return $resultset;  

}

escape it

this refers putting character in front of denote it's meant taken literally:

original statement

select * ikeatable chair '5% off'; 

escaped version

select * ikeatable chair '5\% off' escape '\'; 

yours

select distinct * shares where(company '\%{$id}' or issue_date '\%{$id}') escape '\' 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -