Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $a = !empty($_GET['a']) ? $_GET['a'] : "reset";
- $iduser = !empty($_GET['id']) ? $_GET['id'] : " ";
- $kdb = koneksidatabase();
- $a = @$_GET["a"];
- $sql = @$_POST["sql"];
- switch ($sql) {
- case "insert": sql_insert(); break;
- case "update": sql_update(); break;
- case "delete": sql_delete(); break;
- }
- switch ($a) {
- case "reset" : curd_read(); break;
- case "tambah": curd_create(); break;
- case "edit" : curd_update($iduser); break;
- case "hapus" : curd_delete($iduser); break;
- default : curd_read(); break;
- }
- mysqli_close($kdb);
- function curd_read()
- {
- $hasil = sql_select();
- $i=1;
- ?>
- <H3> MASTER DATA USER AKUN </H3>
- <a href="master_user4.php?a=tambah" >CREATE</a>
- <table border="1" cellpadding="10" cellspacing="0" >
- <tr>
- <td>No</td>
- <td>ID</td>
- <td>Username</td>
- <td>Password</td>
- <td>ID Mahasiswa</td>
- <td>Publish</td>
- <td>Aksi</td>
- </tr>
- <?php
- while($baris = mysqli_fetch_array($hasil))
- {
- ?>
- <tr>
- <td><?= $i; ?></td>
- <td><?= $baris['iduser']; ?></td>
- <td><?= $baris['nmuser']; ?></td>
- <td><?= $baris['password']; ?></td>
- <td><?= $baris['idmahasiswa']; ?></td>
- <td><?= $baris['publish']; ?></td>
- <td>
- <a href="master_user4.php?a=edit&id=<?php echo $baris['iduser']; ?>">UPDATE</a>
- <a href="master_user4.php?a=hapus&id=<?php echo $baris['iduser']; ?>">DELETE</a>
- </td>
- </tr>
- <?php
- $i++;
- }
- ?>
- </table>
- <?php
- mysqli_free_result($hasil);
- }
- ?>
- <?php
- function formeditor($row)
- {
- ?>
- <table>
- <tr>
- <td width="200px">Nama User</td>
- <td><input type="text" name="nmuser" id="nmuser" maxlength="25" size="25" value="<?php echo trim($row["nmuser"]) ?>" ></td>
- </tr>
- <tr>
- <td width="200px">Password</td>
- <td><input type="text" name="password" id="password" maxlength="25" size="25" value="<?php echo trim($row["password"]) ?>" ></td>
- </tr>
- <tr>
- <td width="200px">ID Mahasiswa</td>
- <td><input type="text" name="idmahasiswa" id="idmahasiswa" maxlength="25" size="25" value="<?php echo trim($row["idmahasiswa"]) ?>" ></td>
- </tr>
- <tr>
- <td >PUBLIKASI</td>
- <td >
- <?php $publish = str_replace('"', '"', trim($row["publish"])); ?>
- <input type="radio" name="publish" id="publish" value="T" <?php if($publish=='T' || $publish=='') {echo "checked=\"checked\""; } else {echo ""; } ?> />
- <label>Dipublikasikan</label><br>
- <input type="radio" name="publish" id="publish" value="F" <?php if($publish=='F') {echo "checked=\"checked\""; } else {echo ""; } ?> />
- <label>Tidak dipublikasikan</label>
- </td>
- </tr>
- </table>
- <?php }?>
- <?php
- function curd_create()
- {
- ?>
- <h3>Penambahan Data User</h3><br>
- <a href="master_user4.php?a=reset">Batal</a>
- <br>
- <form action="master_user4.php?a=reset" method="post">
- <input type="hidden" name="sql" value="insert" >
- <?php
- $row = array(
- "nmuser" => "",
- "password" => "",
- "idmahasiswa" => "",
- "publish" => "T");
- formeditor($row)
- ?>
- <p><input type="submit" name="action" value="Simpan" ></p>
- </form>
- <?php } ?>
- <?php
- function curd_update($iduser)
- {
- global $kdb;
- $hasil2 = sql_select_byid($iduser);
- $row = mysqli_fetch_array($hasil2);
- ?>
- <h3>Pengubahan Data User</h3><br>
- <a href="master_user4.php?a=reset">Batal</a>
- <br>
- <form action="master_user4.php?a=reset" method="post">
- <input type="hidden" name="sql" value="update" >
- <input type="hidden" name="iduserx" value="<?php echo $iduser; ?>" >
- <?php
- formeditor($row)
- ?>
- <p><input type="submit" name="action" value="Update" ></p>
- </form>
- <?php } ?>
- <?php
- function curd_delete($iduser)
- {
- global $kdb;
- $hasil2 = sql_select_byid($iduser);
- $row = mysqli_fetch_array($hasil2);
- ?>
- <h3>Penghapusan Data User</h3><br>
- <a href="master_user4.php?a=reset">Batal</a>
- <br>
- <form action="master_user4.php?a=reset" method="post">
- <input type="hidden" name="sql" value="delete" >
- <input type="hidden" name="iduserx" value="<?php echo $iduser; ?>" >
- <h3> Anda yakin akan menghapus data User <?php echo $row['nmuser'];?> </h3>
- <p><input type="submit" name="action" value="Delete" ></p>
- </form>
- <?php } ?>
- <?php
- function koneksidatabase()
- {
- include('../koneksi/koneksi.php');
- return $kdb;
- }
- function sql_select()
- {
- global $kdb;
- $sql = " select * from user ";
- $hasil = mysqli_query($kdb, $sql) or die(mysql_error());
- return $hasil;
- }
- function sql_insert()
- {
- global $kdb;
- global $_POST;
- echo $_POST["nmuser"];
- $sql = " insert into `user` (`nmuser`, `password`, `idmahasiswa`, `publish`) values ( '".$_POST["nmuser"]."', '".$_POST["password"]."', '".$_POST["idmahasiswa"]."', '".$_POST["publish"]."' )";
- mysqli_query($kdb, $sql) or die( mysql_error());
- }
- function sql_select_byid($iduser)
- {
- global $kdb;
- $sql = " select * from user where iduser = ".$iduser;
- $hasil2 = mysqli_query($kdb, $sql) or die(mysql_error());
- return $hasil2;
- }
- function sql_update()
- {
- global $kdb;
- global $_POST;
- $sql = " update `user` set `nmuser` = '".$_POST["nmuser"]."', password = '".$_POST["password"]."', publish = '".$_POST["publish"]."' where iduser = ".$_POST["iduserx"];
- mysqli_query($kdb, $sql) or die( mysql_error());
- }
- function sql_delete()
- {
- global $kdb;
- global $_POST;
- $sql = " delete from `user` where iduser = ".$_POST["iduserx"];
- mysqli_query($kdb, $sql) or die( mysql_error());
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement