Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. <!-- ## The edit button html / php ##-->
  2. <?php
  3.  
  4. if (isset($_POST['edit'])) {
  5.  
  6. try {
  7. $dbh = new PDO('mysql:host=localhost;dbname=bh09uc; charset=utf8','root', '');
  8.  
  9. $sql = "UPDATE devices SET device_processor = :cpu, device_ram = :ram, device_storage = :storage, device_os = :os, device_camera = :camera, device_stock = :stock, device_price = :price, device_image = :image WHERE deviceid=:ID";
  10. //named paramaters
  11. $stmt = $dbh->prepare($sql);
  12.  
  13. $ID = filter_input(INPUT_POST, 'ID');
  14. $stmt->bindValue(':ID', $ID, PDO::PARAM_INT);
  15.  
  16. $cpu = filter_input(INPUT_POST, 'cpu');
  17. $stmt->bindValue(':cpu', $cpu, PDO::PARAM_STR);
  18.  
  19. $ram = filter_input(INPUT_POST, 'ram');
  20. $stmt->bindValue(':ram', $ram, PDO::PARAM_STR);
  21.  
  22. $storage = filter_input(INPUT_POST, 'storage');
  23. $stmt->bindValue(':storage', $storage, PDO::PARAM_STR);
  24.  
  25. $os = filter_input(INPUT_POST, 'os');
  26. $stmt->bindValue(':os', $os, PDO::PARAM_STR);
  27.  
  28. $camera = filter_input(INPUT_POST, 'camera');
  29. $stmt->bindValue(':camera', $camera, PDO::PARAM_STR);
  30.  
  31. $stock = filter_input(INPUT_POST, 'stock');
  32. $stmt->bindValue(':stock', $stock, PDO::PARAM_STR);
  33.  
  34. $price = filter_input(INPUT_POST, 'price');
  35. $stmt->bindValue(':price', $price, PDO::PARAM_STR);
  36.  
  37. $image = filter_input(INPUT_POST, 'image');
  38. $stmt->bindValue(':image', $image, PDO::PARAM_STR);
  39.  
  40.  
  41.  
  42.  
  43. $stmt->execute();
  44. $dbh = null;
  45.  
  46.  
  47. } catch (PDOException $e) {
  48. print "We had an error: " . $e->getMessage() . "<br/>";
  49. die();
  50. }
  51. ?>
  52.  
  53. Device updated.
  54.  
  55. <?php } else {
  56. try {
  57. $dbh = new PDO('mysql:host=localhost;dbname=bh09uc; charset=utf8','root', '');
  58. $sql = "SELECT * FROM devices WHERE deviceid=:ID LIMIT 1";
  59.  
  60. //named paramaters
  61. $stmt = $dbh->prepare($sql);
  62.  
  63. $deviceid = filter_input(INPUT_GET, 'id');
  64. $stmt->bindValue(':ID', $deviceid, PDO::PARAM_INT);
  65.  
  66. $stmt->execute();
  67. $r = $stmt->fetch(PDO::FETCH_ASSOC);
  68. $dbh = null;
  69.  
  70. if (!$r){
  71. print "No phone specified to update";
  72. exit();
  73. }
  74.  
  75. } catch (PDOException $e) {
  76. print "We had an error: " . $e->getMessage() . "<br/>";
  77. die(); //take out?
  78. }
  79. ?>
  80.  
  81.  
  82.  
  83. <!-- <form action="edit-device.php" method="post"> -->
  84. <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
  85. <center><h3> Edit a device </h3></center><br>
  86. ID: <input type="text" readonly name="movieId" value="<?= htmlspecialchars($r['deviceid']); ?>"><br><br>
  87. Processor: <input type="text" name="cpu" value="<?= htmlspecialchars($r['device_processor'])?>"><br><br>
  88. Ram: <input type="text" name="ram" value="<?= htmlspecialchars($r['device_ram'])?>"><br><br>
  89. Storage: <input type="text" name="storage" value="<?= htmlspecialchars($r['device_storage'])?>"><br><br>
  90. OS: <input type="text" name="os" value="<?= htmlspecialchars($r['device_os'])?>"><br><br>
  91. Camera: <input type="text" name="camera" value="<?= htmlspecialchars($r['device_camera'])?>"><br><br>
  92. Stock: <input type="text" name="stock" value="<?= htmlspecialchars($r['device_stock'])?>"><br><br>
  93. Price: <input type="text" name="price" value="<?= htmlspecialchars($r['device_price'])?>"><br><br>
  94. <?php echo '<input type="text" name="image" value="' . $r['device_image'] . '">' . '<br><img src="' . htmlspecialchars($r['device_image']) . '" width="200px" height="250px"></a><br><br>'; ?>
  95.  
  96. <input type="submit" name="edit" value="Edit">
  97. </form>
  98.  
  99. <?php } ?>
  100.  
  101. <!--- ### The delete button php / html ###-->
  102.  
  103. <?php
  104. if (isset($_POST['remove'])) {
  105. $dbx = new PDO('mysql:host=localhost;dbname=bh09uc; charset=utf8','root', '');
  106. $dbx->query('DELETE FROM devices WHERE deviceid =' . $deviceid);
  107. }?>
  108.  
  109. <form action="<?php echo htmlentities($_SERVER['PHP_SELF'] . '?id=' . $deviceid ); ?>" method="post">
  110. <input type="submit" name="remove" value="Remove">
  111. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement