Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include_once("config.php");
- if (isset($_POST['ubah'])) {
- $id = $_POST['id'];
- $name = $_POST['name'];
- $description = (isset($_POST['description']) ? $_POST['description'] : '');
- if (empty($name)) {
- echo "<font color ='red'>Nama tidak boleh dikosongkan.</font><br/>";
- } else {
- $sql = "UPDATE categories SET name=:name, description=:description WHERE id=:id";
- $query = $conn->prepare($sql);
- $query->bindparam(':id', $id);
- $query->bindparam(':name', $name);
- $query->bindparam(':description', $description);
- $query->execute();
- header("Location: index.php");
- }
- }
- ?>
- <?php
- $id = isset($_GET['id']) ? $_GET['id'] : '';
- //selecting data associated with this particular id
- $sql = "SELECT * FROM categories WHERE id=:id";
- $query = $conn->prepare($sql);
- $query->execute(array(':id' => $id));
- while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
- $name = $row['name'];
- $description = $row['description'];
- }
- ?>
- <html>
- <head>
- <title>Ubah Data</title>
- <meta charset="utf-8" />
- <meta name="viewport" content="width=device-width",
- initial-scale=1">
- <link rel="stylesheet" href="css/bootstrap.min.css" />
- <script
- src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"
- integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
- crossorigin="anonymous"
- ></script>
- <script src="js/bootstrap.min.js"></script>
- </head>
- <body style="background:gray">
- <br />
- <div class=container>
- <a href="index.php"><button class='btn btn-primary'>Home</button></a>
- <br /><hr />
- <form name="formubah" method="post" action="ubah.php">
- <table border="0">
- <div class="form-group">
- <label for="name">Nama:</label>
- <input type="text" class="form-control" name="name" value="<?php echo $name; ?>" required>
- </div>
- <div class="form-group">
- <label for="name">Nama:</label>
- <input type="text" class="form-control" name="description" value="<?php echo $description; ?>">
- </div>
- <hr />
- <tr>
- <td><input type="hidden" name="id" value=<?php echo isset($_GET['id']) ? $_GET['id'] : ''; ?>></td>
- <td><input class='btn btn-primary' type="submit" name="ubah" value="Ubah"></td>
- </tr>
- </table>
- </form>
- </body
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement