Advertisement
Guest User

Untitled

a guest
Dec 19th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. <?php
  2. $surname = $_POST['q'];
  3.  
  4. $servername = "localhost";
  5. $username = "root";
  6. $password = "";
  7. $dbname = "testweb";
  8.  
  9. // Create connection
  10. $conn = new mysqli($servername, $username, $password, $dbname);
  11. // Check connection
  12. if ($conn->connect_error) {
  13. die("Connection failed: " . $conn->connect_error);
  14. }
  15.  
  16. $sql = "SELECT id, fname, sname, email FROM contacts";
  17. $sql = $sql . " WHERE sname like '%$surname%'";
  18. echo $sql;
  19. $result = $conn->query($sql);
  20.  
  21. if ($result->num_rows > 0) {
  22. // output data of each row
  23. echo "<table width='80%' border='1'>";
  24. echo "<tr><th>ID</th><th>Name</th><th>Surname</th><th>Email</th></tr>";
  25. while($row = $result->fetch_assoc()) {
  26. echo "<tr>";
  27. echo "<td>" . $row["id"]. "</td><td>" . $row["fname"]. "</td><td>" . $row["sname"]. "</td><td>" . $row["email"]. "</td>";
  28. echo "</tr>";
  29. }
  30. echo "</table>";
  31. } else {
  32. echo "0 results";
  33. }
  34. $conn->close();
  35. echo "<a href=index.html>Search Again?</a>";
  36. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement