Guest User

Untitled

a guest
Jan 12th, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. (ex:)`http://localhost/index.php?id=12`
  2.  
  3. <?php
  4. $userId = $_GET['id'];
  5.  
  6. $servername = "localhost";
  7. $username = "username";
  8. $password = "password";
  9. $dbname = "myDB";
  10.  
  11. // Create connection
  12. $conn = mysqli_connect($servername, $username, $password, $dbname);
  13. // Check connection
  14. if (!$conn) {
  15. die("Connection failed: " . mysqli_connect_error());
  16. }
  17.  
  18. $sql = "SELECT id, firstname, lastname FROM MyGuests where id=$userId";
  19. $result = mysqli_query($conn, $sql);
  20.  
  21. if (mysqli_num_rows($result) > 0) {
  22. // output data of each row
  23. while($row = mysqli_fetch_assoc($result)) {
  24. echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " .
  25. $row["lastname"]. "<br>";
  26. }
  27. } else {
  28. echo "0 results";
  29. }
  30.  
  31. mysqli_close($conn);
  32. ?>
Add Comment
Please, Sign In to add comment