Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. <?php
  2. include_once("config.php");
  3.  
  4. if (isset($_POST['ubah'])) {
  5. $id = $_POST['id'];
  6.  
  7. $name = $_POST['name'];
  8. $description = (isset($_POST['description']) ? $_POST['description'] : '');
  9.  
  10. if (empty($name)) {
  11. echo "<font color ='red'>Nama tidak boleh dikosongkan.</font><br/>";
  12. } else {
  13. $sql = "UPDATE categories SET name=:name, description=:description WHERE id=:id";
  14. $query = $conn->prepare($sql);
  15. $query->bindparam(':id', $id);
  16. $query->bindparam(':name', $name);
  17. $query->bindparam(':description', $description);
  18. $query->execute();
  19. header("Location: index.php");
  20. }
  21. }
  22. ?>
  23. <?php
  24. $id = isset($_GET['id']) ? $_GET['id'] : '';
  25.  
  26. //selecting data associated with this particular id
  27. $sql = "SELECT * FROM categories WHERE id=:id";
  28. $query = $conn->prepare($sql);
  29. $query->execute(array(':id' => $id));
  30.  
  31. while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
  32. $name = $row['name'];
  33. $description = $row['description'];
  34. }
  35. ?>
  36. <html>
  37.  
  38. <head>
  39. <title>Ubah Data</title>
  40. <meta charset="utf-8" />
  41. <meta name="viewport" content="width=device-width",
  42. initial-scale=1">
  43. <link rel="stylesheet" href="css/bootstrap.min.css" />
  44. <script
  45. src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"
  46. integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
  47. crossorigin="anonymous"
  48. ></script>
  49. <script src="js/bootstrap.min.js"></script>
  50. </head>
  51.  
  52. <body style="background:gray">
  53. <br />
  54. <div class=container>
  55. <a href="index.php"><button class='btn btn-primary'>Home</button></a>
  56. <br /><hr />
  57. <form name="formubah" method="post" action="ubah.php">
  58. <table border="0">
  59. <div class="form-group">
  60. <label for="name">Nama:</label>
  61. <input type="text" class="form-control" name="name" value="<?php echo $name; ?>" required>
  62. </div>
  63. <div class="form-group">
  64. <label for="name">Nama:</label>
  65. <input type="text" class="form-control" name="description" value="<?php echo $description; ?>">
  66. </div>
  67. <hr />
  68. <tr>
  69. <td><input type="hidden" name="id" value=<?php echo isset($_GET['id']) ? $_GET['id'] : ''; ?>></td>
  70. <td><input class='btn btn-primary' type="submit" name="ubah" value="Ubah"></td>
  71. </tr>
  72. </table>
  73. </form>
  74. </body
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement