Advertisement
byronwai

search.php

Mar 4th, 2018
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.30 KB | None | 0 0
  1. <?php
  2. include 'base1.php';
  3. ?>
  4. <center>
  5. <table style="text-align:left;">
  6. <tr>
  7. <td><a href="index.php">View Guestbook</a> </td>
  8. <td style="width:20px;"></td>
  9. <td><a href="sign.php">Sign Guestbook</a> </td>
  10. <td style="width:20px;"></td>
  11. <td><a href="delete.php">Delete Guestbook</a></td>
  12. </tr>
  13. </table>
  14. <br />
  15.  
  16. <?php
  17. if (isset($_POST['q'])) {
  18.     $search = $_POST['q'];
  19. } else {
  20.     $search = '';
  21. }
  22.  
  23. if (isset($_POST['lang'])) {
  24.     $lang   = $_POST['lang'];
  25. } else {
  26.     $lang   = 'en';
  27. }
  28.    
  29.  
  30. $host="localhost"; // Host name
  31. $username="root"; // Mysql username
  32. $password=""; // Mysql password
  33. $db_name="webappdb"; // Database name
  34. $tbl_name="guestbook"; // Table name
  35. ?>
  36. <form action="/search.php" method="post">
  37. <center>
  38. <table style="text-align:left;">
  39. <tr>
  40. <td>Search for:<input type="text" name="q" value="<?php echo htmlentities($search);?>" /></td>
  41. <td style="width:20px;"></td>
  42. <td>Language:<select name="lang">
  43. <option value="en"<?php if ($lang == 'en'): echo ' selected="selected"'; endif;?>>EN</option>
  44. <option value="fr"<?php if ($lang == 'fr'): echo ' selected="selected"'; endif; ?>>FR</option>
  45. </select></td>
  46. <td style="width:20px;"></td>
  47. <td><input type="submit" name="" value="Search" /></td>
  48.  
  49. </tr>
  50. </table>
  51. </center>
  52. <br />
  53. </form>
  54. <?php
  55. // Connect to server and select database.
  56. mysql_connect("$host", "$username", "$password")or die("cannot connect server ");
  57. mysql_select_db("$db_name")or die("cannot select DB");
  58.  
  59. $search = mysql_real_escape_string($search);
  60. $q = "SELECT * FROM $tbl_name WHERE comment LIKE '$search%' AND lang = '".$lang."'";
  61. $result=mysql_query($q) or die (mysql_error());
  62. echo "<table style=\"table-layout:fixed; width:700px; text-align:left; background-color:#000; border:solid #666 1px;\">
  63. <tr>
  64. <td style=\"background-color:#222; width:100px;\">ID</td>
  65. <td style=\"background-color:#222; width:100px;\">Name</td>
  66. <td style=\"background-color:#222;\">Comment</td></tr>";
  67.  
  68.  
  69. while ($rows = mysql_fetch_array($result))  
  70. {
  71.     ?>
  72.         <tr><td><a href="comment.php?id=<?php echo $rows['0']; ?>"><?php echo $rows['0']; ?></a></td>
  73. <td ><?php echo $rows[2]; ?></td>
  74. <td><?php echo $rows['4']; ?></td>
  75. </tr>
  76.     <?php
  77. }
  78. ?>
  79. <?php
  80.  
  81. echo "</table></center><br />";
  82.  
  83. mysql_close(); //close database
  84. ?>
  85.  
  86. <br /><br /><br />
  87.  
  88. <?php
  89. include 'base2.php';
  90. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement