Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- ## The edit button html / php ##-->
- <?php
- if (isset($_POST['edit'])) {
- try {
- $dbh = new PDO('mysql:host=localhost;dbname=bh09uc; charset=utf8','root', '');
- $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";
- //named paramaters
- $stmt = $dbh->prepare($sql);
- $ID = filter_input(INPUT_POST, 'ID');
- $stmt->bindValue(':ID', $ID, PDO::PARAM_INT);
- $cpu = filter_input(INPUT_POST, 'cpu');
- $stmt->bindValue(':cpu', $cpu, PDO::PARAM_STR);
- $ram = filter_input(INPUT_POST, 'ram');
- $stmt->bindValue(':ram', $ram, PDO::PARAM_STR);
- $storage = filter_input(INPUT_POST, 'storage');
- $stmt->bindValue(':storage', $storage, PDO::PARAM_STR);
- $os = filter_input(INPUT_POST, 'os');
- $stmt->bindValue(':os', $os, PDO::PARAM_STR);
- $camera = filter_input(INPUT_POST, 'camera');
- $stmt->bindValue(':camera', $camera, PDO::PARAM_STR);
- $stock = filter_input(INPUT_POST, 'stock');
- $stmt->bindValue(':stock', $stock, PDO::PARAM_STR);
- $price = filter_input(INPUT_POST, 'price');
- $stmt->bindValue(':price', $price, PDO::PARAM_STR);
- $image = filter_input(INPUT_POST, 'image');
- $stmt->bindValue(':image', $image, PDO::PARAM_STR);
- $stmt->execute();
- $dbh = null;
- } catch (PDOException $e) {
- print "We had an error: " . $e->getMessage() . "<br/>";
- die();
- }
- ?>
- Device updated.
- <?php } else {
- try {
- $dbh = new PDO('mysql:host=localhost;dbname=bh09uc; charset=utf8','root', '');
- $sql = "SELECT * FROM devices WHERE deviceid=:ID LIMIT 1";
- //named paramaters
- $stmt = $dbh->prepare($sql);
- $deviceid = filter_input(INPUT_GET, 'id');
- $stmt->bindValue(':ID', $deviceid, PDO::PARAM_INT);
- $stmt->execute();
- $r = $stmt->fetch(PDO::FETCH_ASSOC);
- $dbh = null;
- if (!$r){
- print "No phone specified to update";
- exit();
- }
- } catch (PDOException $e) {
- print "We had an error: " . $e->getMessage() . "<br/>";
- die(); //take out?
- }
- ?>
- <!-- <form action="edit-device.php" method="post"> -->
- <form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
- <center><h3> Edit a device </h3></center><br>
- ID: <input type="text" readonly name="movieId" value="<?= htmlspecialchars($r['deviceid']); ?>"><br><br>
- Processor: <input type="text" name="cpu" value="<?= htmlspecialchars($r['device_processor'])?>"><br><br>
- Ram: <input type="text" name="ram" value="<?= htmlspecialchars($r['device_ram'])?>"><br><br>
- Storage: <input type="text" name="storage" value="<?= htmlspecialchars($r['device_storage'])?>"><br><br>
- OS: <input type="text" name="os" value="<?= htmlspecialchars($r['device_os'])?>"><br><br>
- Camera: <input type="text" name="camera" value="<?= htmlspecialchars($r['device_camera'])?>"><br><br>
- Stock: <input type="text" name="stock" value="<?= htmlspecialchars($r['device_stock'])?>"><br><br>
- Price: <input type="text" name="price" value="<?= htmlspecialchars($r['device_price'])?>"><br><br>
- <?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>'; ?>
- <input type="submit" name="edit" value="Edit">
- </form>
- <?php } ?>
- <!--- ### The delete button php / html ###-->
- <?php
- if (isset($_POST['remove'])) {
- $dbx = new PDO('mysql:host=localhost;dbname=bh09uc; charset=utf8','root', '');
- $dbx->query('DELETE FROM devices WHERE deviceid =' . $deviceid);
- }?>
- <form action="<?php echo htmlentities($_SERVER['PHP_SELF'] . '?id=' . $deviceid ); ?>" method="post">
- <input type="submit" name="remove" value="Remove">
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement