Advertisement
anticims19

update.php

Oct 7th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.28 KB | None | 0 0
  1. <?php
  2. include "./inc/config.php";
  3. include "./inc/function.php";
  4. $id = $_SESSION['id'];
  5. ?>
  6. <ul class="breadcrumb">
  7.   <li><a href="./">Home</a></li>
  8.   <li><a href="?page=<?php echo $page ;?>"><?php echo ucfirst($page) ; ?></a></li>
  9.   <li class="active"><?php echo ucfirst($action) ; ?> Data</li>
  10. </ul>
  11.       <?php
  12.         include "./inc/config.php";
  13.         $query=mysql_query("SELECT * from t_user WHERE id='$_GET[id]' " ) or die (mysql_error());  //mengambil data tabel mahasiswa dan memasukkan nya ke variabel query
  14.         $no=1;                    //membuat nomor pada tabel
  15.         while($lihat=mysql_fetch_array($query)){    //mengeluarkan isi data dengan mysql_fetch_array dengan perulangan
  16.       ?>
  17. <form class="form-horizontal" method="POST">
  18.   <fieldset>
  19.     <legend>Update Data Admin</legend>
  20.     <div class="form-group">
  21.       <label class="col-sm-2 control-label">Username</label>
  22.       <div class="col-sm-3">
  23.         <input type="text" class="form-control" readonly="" name="username" value="<?php echo $lihat['username'] ;?>">
  24.         </select>
  25.       </div>
  26.     </div>
  27.     <div class="form-group">
  28.       <label class="col-sm-2 control-label">Password</label>
  29.       <div class="col-sm-3">
  30.         <input type="password" class="form-control" name="password" id="password" placeholder="masukkan password baru">
  31.       </div>
  32.      
  33.     </div>
  34.     <div class="form-group">
  35.       <label class="col-sm-2 control-label">Nama</label>
  36.       <div class="col-sm-3">
  37.         <input type="text" class="form-control" readonly="" name="nama" value="<?php echo $lihat['nama'] ;?>">
  38.         </select>
  39.       </div>
  40.     </div>
  41.     <div class="form-group">
  42.       <label class="col-sm-2 control-label">Level</label>
  43.       <div class="col-sm-3">
  44.           <select name="level" class="form-control">
  45.         <option value="">--Pilih Level--</option>
  46.         <option <?php if($lihat['level'] == "admin"){echo "selected";} ?> value="admin">Admin</option>
  47.         <option <?php if($lihat['level'] == "operator"){echo "selected";} ?> value="operator">Operator</option>
  48.       </select>
  49.       </div>
  50.     </div>
  51.     <div class="form-group">
  52.       <label class="col-sm-2 control-label">Status</label>
  53.       <div class="col-sm-3">
  54.         <select name="status" class="form-control">
  55.           <option <?php if( $lihat['aktif']=='1'){echo "selected"; } ?> value='1'>Aktif</option>
  56.           <option <?php if( $lihat['aktif']=='0'){echo "selected"; } ?> value='0'>Non Aktif</option>          
  57.         </select>
  58.       </div>
  59.     </div>
  60.    
  61.    <input type="hidden" name="id" value="<?php echo $lihat['id'] ;?>">
  62.     <div class="form-group">
  63.       <div class="col-sm-10 col-sm-offset-2">
  64.         <button type="reset" class="btn btn-primary btn-sm"><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> Reset</button>
  65.         <button type="submit" name="simpan" class="btn btn-success btn-sm"><span class="glyphicon glyphicon-ok" aria-hidden="true"></span> Simpan</button>
  66.         <a href="?page=admin" class="btn btn-info btn-sm"><span class="glyphicon glyphicon-arrow-left" aria-hidden="true"></span> Batal </a>
  67.       </div>
  68.     </div>
  69.   </fieldset>
  70.  
  71.  
  72. </form>
  73. <?php
  74. };
  75. ?>
  76.  
  77.   <?php
  78.   if(isset($_POST['simpan'])){
  79.     $username = $_POST['username'];
  80.     $nama = $_POST['nama'];
  81.     $password = md5($_POST['password']);
  82.     $level = $_POST['level'];
  83.     $status = $_POST['status'];
  84.     $id = $_POST['id'];
  85.  
  86.     $query=mysql_query("UPDATE t_user SET username='$username', password='$password', nama='$nama', level='$level', aktif='$status' WHERE id='$id'")or die(mysql_error());
  87.     // if($query){
  88.     //   echo "1";
  89.     //   echo $status;
  90.     // }else{
  91.     //   echo "0";
  92.     //   echo $status;
  93.     // }
  94.     echo '<META HTTP-EQUIV="Refresh" Content="0; URL=?page=admin">';
  95.     }
  96.  
  97.  
  98.   ?>
  99.  
  100.   <script>
  101.     function random() {
  102.  
  103.         var text = "";
  104.  
  105.         var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  106.  
  107.  
  108.  
  109.           for (var i = 0; i < 5; i++)
  110.  
  111.             text += possible.charAt(Math.floor(Math.random() * possible.length));
  112.  
  113.  
  114.  
  115.         return text;
  116.  
  117.     }
  118.  
  119.     function generatePass() {
  120.       alert('Berhasil Generate Password');
  121.       var x = random();
  122.  
  123.       console.log(x);
  124.  
  125.       $("#password").val(x);
  126.     }
  127.   </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement