Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php include('server.php');
- //fetch the record to be updated
- if (isset($_GET['edit'])) {
- $id = $_GET['edit'];
- $update = true;
- $record = mysqli_query($db, "SELECT * FROM info WHERE id=$id");
- if (count($record) == 0 ) {
- $n = mysqli_fetch_array($record);
- $name = $n['name'];
- $address = $n['address'];
- }
- }
- ?>
- <!doctype html>
- <html>
- <head>
- <TITLE>CRUD</TITLE>
- <link rel="stylesheet" type"text/css" href="style.css">
- </head>
- <body>
- <?php if (isset($_SESSION['message'])): ?>
- <div class="msg">
- <?php
- echo $_SESSION['message'];
- unset($_SESSION['message']);
- ?>
- </div>
- <?php endif ?>
- <table>
- <thead>
- <tr>
- <th>name</th>
- <th>Address</th>
- <th colspan="2">ACTION</th>
- </tr>
- </thead>
- <?php while ($row = mysqli_fetch_array($results)) { ?>
- <tr>
- <td><?php echo $row['name']; ?></td>
- <td><?php echo $row['address']; ?></td>
- <td>
- <a class="edit_btn" href="index.php?edit=<?php echo $row['id']; ?>">Edit</a>
- </td>
- <td>
- <a class="del_btn" href="server.php?del=<?php echo $row['id']; ?>">Delete</a>
- </td>
- </tr >
- <?php } ?>
- </tbody>
- </table>
- <form method="post" action="server.php">
- <input type="hidden" name="id" value="<?php echo $id; ?>">
- </div>
- <div class="input-group">
- <label>Name</label>
- <input type="text" name="name" value="<?php echo $name; ?>">
- </div>
- <div class="input-group">
- <label>Address</label>
- <input type="text" name="address" value="<?php echo $address; ?>">
- </div>
- <div class="input-group">
- <?php if ($update == false): ?>
- <button class="btn" type="submit" name="save" >Save</button>
- <?php else: ?>
- <button class="btn" type="submit" name="update" >update</button>
- <?php endif ?>
- </div>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement