Advertisement
Guest User

Untitled

a guest
Jul 10th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. <a href="www.mysite.com/showimage.php?id=1">Show image 1</a>
  2.  
  3. <?php
  4. $imageid = $_GET['id'];
  5.  
  6. $servername = ...;
  7. $username = ...;
  8. $password = ...;
  9. $dbname = ...;
  10.  
  11. $conn = new mysqli($servername, $username, $password, $dbname);
  12.  
  13. if ($conn->connect_error) {
  14. die("Connection to MySQL failed: " . $conn->connect_error);
  15. }
  16.  
  17. htmlspecialchars($imageid);
  18. stripslashes($imageid);
  19. mysqli_real_escape_string($conn, $imageid);
  20.  
  21.  
  22. $sql = "SELECT * FROM images WHERE id = '$imageid'";
  23. $result = $conn->query($sql);
  24.  
  25.  
  26. if (is_object($result) && $result->num_rows > 0) {
  27.  
  28. while($row = $result->fetch_assoc())
  29. {
  30. // Replace "image, image_name ecc." with the columns of the table
  31. echo $row["image"];
  32. echo "Name: " . $row["image_name"];
  33. echo "Info: " . $row["image_useful_info"];
  34. echo "Price: " . $row["image_price"];
  35. }
  36. $conn->close();
  37. die();
  38. }
  39. else
  40. echo "The image you requested was not found.";
  41. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement