Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include 'crud.php';
- $user = new crud();
- $page = isset($_GET['p'])?$_GET['p']:'';
- if($page == "add") {
- $nama = $_POST['nm'];
- $kota = $_POST['kt'];
- $email = $_POST['em'];
- $query = $user->add($nama, $kota, $email);
- if($query == "Success") {
- echo "Sucess add";
- }
- } elseif($page == 'edit') {
- $id = $_POST['id'];
- $nama = $_POST['nm'];
- $kota = $_POST['kt'];
- $email = $_POST['em'];
- $query = $user->update($id, $nama, $kota, $email);
- } elseif($page == "delete") {
- $id = $_GET['id'];
- $query = $user->delete($id);
- } else {
- $show = $user->show();
- while($data = $show->fetch(PDO::FETCH_OBJ)) {
- ?>
- <tr>
- <td><?php echo $data->user_nama ?></td>
- <td><?php echo $data->user_kota ?></td>
- <td><?php echo $data->user_email ?></td>
- <td>
- <div class="btn-group">
- <button class="btn btn-warning" data-toggle="modal" data-target="#edit-<?php echo $data->user_id ?>">Edit</button>
- <!-- Modal -->
- <div class="modal fade" id="edit-<?php echo $data->user_id ?>" tabindex="-1" role="dialog" aria-labelledby="editLabel-<?php echo $data->user_id ?>" aria-hidden="true">
- <div class="modal-dialog" role="document">
- <div class="modal-content">
- <div class="modal-header">
- <h5 class="modal-title" id="editLabel-<?php echo $data->user_id ?>">Update Data</h5>
- <button type="button" class="close" data-dismiss="modal" aria-label="Close">
- <span aria-hidden="true">×</span>
- </button>
- </div>
- <form>
- <div class="modal-body">
- <input type="hidden" id="<?php echo $data->user_id ?>" value="<?php echo $data->user_id ?>">
- <div class="form-group">
- <label for="nm">Nama</label>
- <input type="text" class="form-control" id="nm-<?php echo $data->user_id ?>" value="<?php echo $data->user_nama ?>">
- </div>
- <div class="form-group">
- <label for="kt">Kota</label>
- <input type="text" class="form-control" id="kt-<?php echo $data->user_id ?>" value="<?php echo $data->user_kota ?>">
- </div>
- <div class="form-group">
- <label for="em">Email</label>
- <input type="email" class="form-control" id="em-<?php echo $data->user_id ?>" value="<?php echo $data->user_email ?>">
- </div>
- </div>
- <div class="modal-footer">
- <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
- <button type="submit" onclick="updateData(<?php echo $data->user_id ?>)" class="btn btn-primary">Update</button>
- </div>
- </form>
- </div>
- </div>
- </div>
- <button onclick="deleteData(<?php echo $data->user_id ?>)" class="btn btn-danger">Delete</button>
- </div>
- </td>
- </tr>
- <?php
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement