Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php include "config/koneksi.php";
- if(isset($_GET['hapus'])){
- $hapus="delete from user where id='$_GET[id]'";
- $war=mysqli_query($con,$hapus);
- if($war){
- echo "<script>alert('Data Terhapus')</script>";
- }
- }
- if(isset($_POST['simpan'])){
- $sim="insert into user values (null,'$_POST[username]','$_POST[password]')";
- $pan=mysqli_query($con,$sim);
- if($pan){
- echo "<script>alert('Data Tersimpan')</script>";
- echo "<script>document.location.href='k_user.php';</script>";
- }
- }
- if (isset($_GET['edit'])) {
- $et = "SELECT * FROM user WHERE id = '$_GET[id]'";
- $it = mysqli_query($con,$et);
- $edit = mysqli_fetch_array($it);
- }
- if (isset($_POST['update'])) {
- $up = "update user set nama='$_POST[nama_user]',username='$_POST[username]',password='$_POST[password]' WHERE id = '$_POST[kode_user]'";
- $da = mysqli_query($con,$up);
- if($da){
- echo "<script>alert('Data Terupdate');document.location.href='k_user.php';</script>";
- }else{
- echo "<script>alert('Data Gagal Terupdate ');document.location.href='k_user.php';</script>";
- }
- }
- ?>
- <html>
- <head><title>Form Kelola User</title></head>
- <form method="post">
- <table border=1>
- <tr>
- <td>ID</td>
- <td>:</td>
- <td><input type="text" name="kode_user" disabled="true" value="<?php echo @$edit[0] ?>"></td>
- </tr>
- <tr>
- <tr>
- <td>Username</td>
- <td>:</td>
- <td><input type="text" name="username" value="<?php echo @$edit[1] ?>"></td>
- </tr>
- <tr>
- <td>Password</td>
- <td>:</td>
- <td><input type="text" name="password" value="<?php echo @$edit[2] ?>"></td>
- </tr>
- <tr>
- <td colspan="2"></td>
- <td>
- <?php if(isset($_GET['edit'])){ ?>
- <input type="submit" name="update" value="Update">
- <?php }else{ ?>
- <input type="submit" name="simpan" value="Simpan">
- <?php } ?>
- <input type="submit" name="kembali" value="Logout">
- </td>
- </tr>
- <table border=1>
- <tr>
- <input type="text" name="tcari" value=<?php echo @$_POST['tcari'] ?>>
- <input type="submit" name="cari" value="Cari">
- <input type="submit" name="R" value="Reset">
- <td>No</td>
- <td>ID</td>
- <td>Username</td>
- <td>Password</td>
- <td>Aksi</td>
- </tr>
- <?php
- $sql="select * from user";
- if(isset($_POST['cari'])){
- $sql="select * from user where nama like'%$_POST[tcari]%'";
- }
- if(isset($_POST['R'])){
- $sql="select * from user";
- echo "<script>document.location.href='k_user.php';</script>";
- }
- $qry=mysqli_query($con,$sql);
- $no=0;
- while($data=mysqli_fetch_array($qry)){
- $no++;
- ?>
- <tr>
- <td><?php echo $no ?></td>
- <td><?php echo $data[0] ?></td>
- <td><?php echo $data[1] ?></td>
- <td><?php echo $data[2] ?></td>
- <td><a href="k_user.php?hapus&id=<?php echo $data[0] ?>">Hapus</a> || <a href="k_user.php?edit&id=<?php echo $data[0] ?>">Edit</a></td>
- </tr>
- <?php } ?>
- </form>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement