SHARE
TWEET

Untitled

a guest Oct 3rd, 2017 28 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.   if(isset($_GET['edit_user'])){
  3.       $the_user_id=$_GET['edit_user'];
  4.      
  5.       $query="SELECT * FROM users WHERE user_id=$the_user_id ";
  6.                                 $select_users_query=mysqli_query($connection,$query);
  7.                                
  8.                                 while($row=mysqli_fetch_assoc($select_users_query)){
  9.                                 $user_id=$row['user_id'];
  10.                                 $username=$row['username'];
  11.                                 $user_password=$row['user_password'];
  12.                                 $user_firstname=$row['user_firstname'];
  13.                                 $user_lastname=$row['user_lastname'];
  14.                                 $user_email=$row['user_email'];
  15.                                 $user_image=$row['user_image'];
  16.                                 $user_role=$row['user_role'];
  17.                  }
  18.       ?>
  19.      
  20.     <?php
  21.  
  22.  
  23.   if(isset($_POST['edit_user'])){
  24.      
  25.       $user_firstname=$_POST['user_firstname'];
  26.       $user_lastname=$_POST['user_lastname'];
  27.       $user_role=$_POST['user_role'];
  28.      
  29.       //$post_image=$_FILES['image']['name'];
  30.       //$post_image_temp=$_FILES['image']['tmp_name'];
  31.      
  32.       $username=$_POST['username'];
  33.       $user_email=$_POST['user_email'];
  34.       $user_password=$_POST['user_password'];
  35.       $post_date=date('d-m-y');
  36.      
  37.      
  38.      // move_uploaded_file($post_image_temp,"../images/$post_image");
  39.      
  40.      // $query="SELECT randSalt FROM users";
  41.      // $select_randsalt_query=mysqli_query($connection,$query);
  42.      // if(!$select_randsalt_query){
  43.     //      die("Query Failed".mysqli_error($connection));
  44.      // }
  45.      // $row=mysqli_fetch_array($select_randsalt_query);
  46.     //  $salt=$row['randSalt'];
  47.     //  $hashed_password=crypt($user_password,$salt);
  48.      
  49.       if(!empty($user_password)){
  50.           $query_password="SELECT user_password FROM users WHERE user_id=$the_user_id";
  51.           $get_user_query=mysqli_query($connection,$query_password);
  52.           confirm($get_user_query);
  53.          
  54.           $row=mysqli_fetch_array($get_user_query);
  55.           $db_user_password=$row['user_password'];
  56.      
  57.           if($db_user_password!=$user_password){
  58.              $hashed_password=password_hash($user_password,PASSWORD_BCRYPT,array('cost'=>12));
  59.           }
  60.      
  61.              $query= "UPDATE users SET ";
  62.              $query .="user_firstname = '{$user_firstname}', ";
  63.              $query .="user_lastname = '{$user_lastname}', ";
  64.              $query .="user_role = '{$user_role}', ";
  65.              $query .="username = '{$username}', ";
  66.              $query .="user_email = '{$user_email}', ";
  67.              $query .="user_password = '{$hashed_password}' ";
  68.              $query .="WHERE user_id = '{$the_user_id}' ";
  69.              
  70.              $edit_user_query=mysqli_query($connection,$query);
  71.              
  72.              confirm($edit_user_query);
  73.      
  74.       echo "User Updated " . " " . "<a href='users.php'>View Users</a>";
  75.    }
  76.   }
  77.  }else{
  78.       header("Location: index.php");
  79.   }
  80.  
  81. ?>
  82.  <form action="" method="post" enctype="multipart/form-data">
  83.  
  84.    <div class="form-group">
  85.      <label for="user_firstname">Firstname</label>
  86.       <input type="text" value="<?php echo $user_firstname; ?>" class="form-control" name="user_firstname">
  87.    </div>
  88.    
  89.   <div class="form-group">
  90.      <label for="user_lastname">Lastname</label>
  91.       <input type="text" value="<?php echo $user_lastname; ?>" class="form-control" name="user_lastname">
  92.    </div>
  93.    
  94.   <div class="form-group">
  95.       <select name="user_role" id="">
  96.       <!-- <option value="subscriber"><?php  //echo $user_role; ?></option> -->
  97.        <option value='admin' <?php if($user_role=='admin') echo 'selected'; ?>>admin</option>
  98.        <option value='subscriber' <?php if($user_role=='subscriber') echo 'selected'; ?>>subscriber</option>
  99.       </select>
  100.   </div>
  101.  <!--     Similar to above used div but more simple
  102.   <div>
  103.       <select name="user_role" id="">
  104.           <option value="<?php echo $user_role; ?>"><?php echo $user_role; ?></option>
  105.           <?php
  106.            if($user_role=='admin'){
  107.                echo "<option value='subscriber'>subscriber</option>";
  108.            }else{
  109.              echo "<option value='admin'>admin</option>";  
  110.            }
  111.           ?>
  112.       </select>
  113.   </div>      
  114.   -->      
  115.  
  116. <!--  
  117.   <div class="form-group">
  118.      <label for="post_image">Post Image</label>
  119.       <input type="file" name="image">
  120.    </div>
  121.  -->  
  122.   <div class="form-group">
  123.      <label for="username">Username</label>
  124.       <input type="text" value="<?php echo $username; ?>" class="form-control" name="username">
  125.    </div>
  126.    
  127.   <div class="form-group">
  128.      <label for="user_email">Email</label>
  129.       <input type="text" value="<?php echo $user_email; ?>" class="form-control" name="user_email">
  130.    </div>
  131.    
  132.    <div class="form-group">
  133.      <label for="user_password">Password</label>
  134.       <input type="password" value="<?php echo $user_password; ?>" class="form-control" name="user_password">
  135.    </div>
  136.    
  137.   <div class="form-group">
  138.      <input class="btn btn-primary" type="submit" name="edit_user" value="Update User">
  139.    </div>
  140.    
  141. </form>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top