Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>Untitled Document</title>
- <style type="text/css">
- <!--
- #form1 table tr td {
- text-align: center;
- }
- -->
- </style>
- </head>
- <?PHP
- include('koneksi.php');
- //SCRIPT untuk save dan simpan baru
- if($_POST){
- $id = $_POST['id'] ;
- $username = $_POST['username'];
- $password = $_POST['password'];
- if (empty($username) || empty($password)){
- echo"Username atau Password tidak boleh kosong";
- }else{
- //untuk ngecek kalo variabel idnya ada perintah sql yang di jalannin sql untuk edit kalo variabel idnya kosong perintah yang di jalanin sql untuk save
- if(!empty($id)){
- $simpan = mysql_query("UPDATE user SET username = '$username', password = '$password' WHERE id = '$id';");
- }else{
- $simpan = mysql_query("INSERT INTO user (`id`, `username`, `password`) VALUES ('NULL', '$username', '$password')");
- }
- if($simpan){
- echo"<script>alert('Data tersimpan!');document.location.href='login.php';</script>";
- }
- else{
- echo"<script>alert('Data gagal tersimpan!');document.location.href='login.php';</script>";
- }
- }
- }
- //Kalo get edit, mengambil data dan sebagainya dari database
- if(isset($_GET['edit'])){
- $sql = "SELECT * FROM user WHERE id = '$_GET[id]'";
- $query = mysql_query($sql);
- $r = mysql_fetch_array($query);
- }
- //SCRIPT HAPUS
- if(isset($_GET['hapus'])){
- $hapus = mysql_query("DELETE FROM user where id = '$_GET[id]'");
- if($hapus){
- echo"Data Terhapus!";
- }
- else{
- echo"Data Gagal Terhapus!";
- }
- }
- ?>
- <body>
- <form id="form1" name="form1" method="post" action="">
- <input type="hidden" name="id" value="<?php echo (isset($r))? $r['id'] : '';?>">
- <table width="270" border="0" cellspacing="1" cellpadding="2">
- <tr>
- <td colspan="2">FORM USER</td>
- </tr>
- <tr>
- <td width="96">Username</td>
- <td width="163"><label>
- <input type="text" name="username" id="textfield" value="<?php echo (isset($r))? $r['username'] : '';?>"/>
- </label></td>
- </tr>
- <tr>
- <td>Password</td>
- <td><label>
- <input type="text" name="password" id="textfield2" value="<?php echo (isset($r))? $r['password'] : '';?>"/>
- </label></td>
- </tr>
- <tr>
- <td colspan="2"><label>
- <input type="submit" name="button" id="button" value="Submit" />
- <input type="reset" name="button2" id="button2" value="Cancel" />
- </label></td>
- </tr>
- </table>
- </form>
- <table>
- <tr>
- <td>No</td>
- <td>Usenname</td>
- <td>Password</td>
- </tr>
- <?php
- $sql = "SELECT * FROM user ";
- $query = mysql_query($sql);
- $no = 0;
- while($row = mysql_fetch_array($query)){
- $no++;
- ?>
- <tr>
- <td><?php echo $no; ?></td>
- <td><?php echo $row['1'];?></td>
- <td><?php echo $row['password']; ?></td>
- <td><a href="?edit&id=<?php echo $row['id']; ?>">Edit</a> | <a href="?hapus&id=<?php echo $row['id']; ?>">Delete</a></td>
- </tr>
- <?php
- }
- ?>
- </table>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement