Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Miniblocket</title>
  5.  
  6. <!-- Latest compiled and minified Bootstrap CSS -->
  7. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
  8.  
  9. </head>
  10. <body>
  11.  
  12.  
  13. <!-- container -->
  14. <div class="container">
  15.  
  16. <div class="page-header">
  17. <h1>Läs annons</h1>
  18. </div>
  19.  
  20. <?php
  21. // get passed parameter value, in this case, the record ID
  22. // isset() is a PHP function used to verify if a value is there or not
  23. $id=isset($_GET['id']) ? $_GET['id'] : die('ERROR: Record ID not found.');
  24.  
  25. //include database connection
  26. include 'config/database.php';
  27.  
  28. // read current record's data
  29. try {
  30. // prepare select query
  31. $query = "SELECT id, name, description, price, image FROM products WHERE id = ? LIMIT 0,1";
  32. $stmt = $con->prepare( $query );
  33.  
  34. // this is the first question mark
  35. $stmt->bindParam(1, $id);
  36.  
  37. // execute our query
  38. $stmt->execute();
  39.  
  40. // store retrieved row to a variable
  41. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  42.  
  43. // values to fill up our form
  44. $name = $row['name'];
  45. $description = $row['description'];
  46. $price = $row['price'];
  47. $image = htmlspecialchars($row['image'], ENT_QUOTES);
  48. }
  49.  
  50. // show error
  51. catch(PDOException $exception){
  52. die('ERROR: ' . $exception->getMessage());
  53. }
  54. ?>
  55.  
  56. <!--we have our html table here where the record will be displayed-->
  57. <table class='table table-hover table-responsive table-bordered'>
  58. <tr>
  59. <td>Titel</td>
  60. <td><?php echo htmlspecialchars($name, ENT_QUOTES); ?></td>
  61. </tr>
  62. <tr>
  63. <td>Beskrivning</td>
  64. <td><?php echo htmlspecialchars($description, ENT_QUOTES); ?></td>
  65. </tr>
  66. <tr>
  67. <td>Pris</td>
  68. <td><?php echo htmlspecialchars($price, ENT_QUOTES); ?></td>
  69. </tr>
  70. <tr>
  71. <td>Bild</td>
  72. <td>
  73. <?php echo $image ? "<img src='uploads/{$image}' style='width:300px;' />" : "No image found."; ?>
  74. </td>
  75. </tr>
  76. <tr>
  77. <td></td>
  78. <td>
  79. <a href='index.php' class='btn btn-danger'>Tillbaka till annonser</a>
  80. </td>
  81. </tr>
  82. </table>
  83.  
  84. </div> <!-- end .container -->
  85.  
  86. <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
  87. <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
  88.  
  89. <!-- Latest compiled and minified Bootstrap JavaScript -->
  90. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  91.  
  92. </body>
  93. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement