Guest User

Untitled

a guest
Jan 20th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. <form action="result.php" method="POST">
  2. <h1>Search</h1>
  3. <input type="text" name="q"></input><br /><br />
  4. <input type="submit" id="submit" value="Search"></input>
  5. </form>
  6.  
  7. <?php
  8. $servername = "localhost";
  9. $username = "myusername";
  10. $password = "mypassword";
  11. $dbname = "mydb";
  12.  
  13. // Create connection
  14. $conn = new mysqli($servername, $username, $password, $dbname);
  15. // Check connection
  16.  
  17. if ($conn->connect_error) {
  18. die("Connection failed: " . $conn->connect_error);
  19. }
  20.  
  21. $mysqli->set_charset("utf8");
  22. if (isset($_REQUEST['q'])){
  23. $target= $_REQUEST['q'];
  24. $sql = " SELECT *
  25. FROM TABLE1
  26. WHERE name
  27. LIKE '%$target%'";
  28.  
  29. $result = $mysqli->query($sql)
  30. or die($mysqli->error . "<pre>$sql</pre>");
  31. while ($row = $result->fetch_assoc()){
  32. echo $row["number"] . " " . $row["name"]. " " . $row["hp"] . "<br>";
  33. }
  34. }
  35. else {
  36. echo "0 results";
  37. }
  38. ?>
Add Comment
Please, Sign In to add comment