Advertisement
gitlez

YA: PHP Search Layout 20130614195000AAV5Uey

Jun 14th, 2013
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!-- Yahoo Answers: http://answers.yahoo.com/question/index?qid=20130614195000AAV5Uey
  2. <form action="show.php" method="post">
  3. <input type="text" value="Enter Site ID" name="a" class="textfield_effect" maxlength="30" onfocus="this.value=''">
  4. </td>
  5. </tr>
  6. <tr>
  7.     <td align="center" style="font-family:Calibri">
  8.     <input type="submit"    value=""/>
  9. </form>
  10.  
  11.  
  12. <?php
  13. echo "<table border='1'>
  14.    <tr>
  15.        <th>ID</th>
  16.        <th>Post Code</th>
  17.        <th>Taxi Name</th>
  18.        <th>Price per mile</th>
  19.        <th>Rating</th>
  20.        <th>Location</th>
  21.        <th>Are they online?</th>
  22.        <th>Are they busy?</th>
  23.    </tr>" . PHP_EOL;
  24.  
  25. if( $_SERVER['REQUEST_METHOD'] === 'POST'){
  26.     $con = mysqli_connect("mysql.crunkboxhost.com","CHANGED","CHANGED","CHANGED");
  27.     // Check connection
  28.     if (mysqli_connect_errno()) {
  29.         echo '<tr><td colspan="8">Failed to connect to MySQL: </td></tr><tr><td colspan="8">' . mysqli_connect_error($con) . '</td></tr>';
  30.     }else{
  31.  
  32.         $a = mysqli_real_escape_string( trim( $_POST["a"] ) ); // SQL Injection protection (Not Best, but better than nothing)
  33.         $result = mysqli_query($con,"SELECT * FROM datasearch WHERE TAXINAME LIKE '%$a%' LIMIT 0,30"); // Don't forget the wildcards
  34.         if( !$result ){ // Malformed Query Statement
  35.             echo '<tr><td colspan="8">Internal Error: </td></tr><tr><td colspan="8">' . mysqli_error($con) . '</td></tr>';
  36.         }else if( $result->num_rows === 0){ // No Rows Returned / Not matches
  37.             echo '<tr><td colspan="8">No results found for "' . $a . '".</td></tr>';
  38.         }else{ // Matches
  39.             // $query = "SELECT * FROM datasearch WHERE ID LIKE '%".$_POST['search']."%'"; // No IDEA what this is trying to accomplish, unless it's some attempt at a caching system
  40.  
  41.             while($row = mysqli_fetch_assoc($result)) {
  42.                 echo "<tr>";
  43.                 echo "<td>" . $row['ID'] . "</td>";
  44.                 echo "<td>" . $row['POSTCODE'] . "</td>";
  45.                 echo "<td>" . $row['TAXINAME'] . "</td>";
  46.                 echo "<td>" . $row['PRICEPERMILE'] . "</td>";
  47.                 echo "<td>" . $row['RATING'] . "</td>";
  48.                 echo "<td>" . $row['LOCATION'] . "</td>";
  49.                 echo "<td>" . $row['ONLINE'] . "</td>";
  50.                 echo "<td>" . $row['BUSY'] . "</td>";
  51.                 echo "</tr>";
  52.             }
  53.         }
  54.        
  55.     }
  56.     if( is_resource($con) ){
  57.         mysqli_close($con);
  58.     }
  59. }else{
  60.     echo '<tr><td colspan="8">Please Enter Site ID to search.</td></tr>';
  61. }
  62. echo "</table>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement