Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.61 KB | None | 0 0
  1. <?php
  2. //admin can edit user information
  3. echo "<link rel='stylesheet' type='text/css' href='../CSS/home_css.css' />";
  4. session_start();
  5. include_once("../footer.php");
  6. require ("../db_connection.php");
  7. include_once ("profile_admin.php");
  8. $query = "SELECT * FROM `users`";
  9. $result = mysqli_query($conn, $query);
  10.    
  11.     //print_r($row);
  12.  
  13. //{
  14. /*if (isset($_POST['username']) && isset($_POST['password'])){
  15.         $id = "SELECT id FROM `users`";
  16.         $username = $_POST['username'];
  17.         $email = $_POST['email'];
  18.         $password = $_POST['password'];
  19.         $first_name = $_POST['first_name'];
  20.         $last_name = $_POST['last_name'];          
  21.         $query1 = "UPDATE `users` SET username='$username',password='$password',
  22.                     email='$email',
  23.                     first_name='$first_name',
  24.                     last_name='$last_name' WHERE id='$id'";
  25.                    
  26.                    
  27.                    
  28.         $result1 = mysqli_query($conn, $query1);
  29.         if($result1){
  30.         echo "<script type='text/javascript'>alert('User Edited!');</script>";
  31.         }
  32.        
  33.         else{
  34.         echo "<script type='text/javascript'>alert('User not Edited!')</script>";
  35.         }
  36.    
  37.     }
  38. //}*/
  39. ?>
  40. <h2>All Users:</h2>
  41. <html>
  42. <head>
  43. <style>
  44. table {
  45.   font-family: arial, sans-serif;
  46.   border-collapse: collapse;
  47.   width: 100%;
  48. }
  49.  
  50. td, th {
  51.   border: 1px solid #dddddd;
  52.   text-align: left;
  53.   padding: 8px;
  54. }
  55.  
  56. tr:nth-child(even) {
  57.   background-color: #dddddd;
  58. }
  59. </style>
  60. </head>
  61. <body>
  62. <table id="myTable">
  63. <?php
  64.         echo "<tr>";
  65.         echo "<th>"."ID"."</th>";
  66.         echo "<th>".'Username'."</th>";
  67.         echo "<th>".'Password'."</th>";
  68.         echo "<th>".'Email'."</th>";
  69.         echo "<th>".'First Name'."</th>";
  70.         echo "<th>".'Last Name'."</th>";
  71.         echo "</tr>";
  72.     if(!isset($_GET['id'])){
  73.         while ($row = mysqli_fetch_array($result)){
  74.         //$editUser=$row['username'];
  75.             echo "<tr>";
  76.             echo "<td><a href='edit_user.php?id=".$row["id"]."'>".$row["id"]."</a></td>";
  77.             echo "<td>".$row["username"]."</td>";
  78.             echo "<td>".$row["password"]."</td>";
  79.             echo "<td>".$row["email"]."</td>"; 
  80.             echo "<td>".$row["first_name"]."</td>";
  81.             echo "<td>".$row["last_name"]."</td>";
  82.             echo "</tr>";
  83.             }
  84.     }
  85.    
  86.     else{
  87.         $query="SELECT * FROM `users` WHERE `id`= {$_GET['id']}";
  88.         $result=mysqli_query($conn,$query);
  89.         $row = mysqli_fetch_assoc($result);
  90.        
  91.         $num = $_GET['id'];
  92.        
  93.         echo "<tr>";
  94.         echo "<td><a href='edit_user.php?id=".$row["id"]."'>".$row["id"]."</a></td>";
  95.         echo "<td>".$row["username"]."</td>";
  96.         echo "<td>".$row["password"]."</td>";
  97.         echo "<td>".$row["email"]."</td>"; 
  98.         echo "<td>".$row["first_name"]."</td>";
  99.         echo "<td>".$row["last_name"]."</td>";
  100.         echo "</tr>";
  101.         //if ($result == true){
  102.        
  103.        
  104.         if(isset($_POST['submit'])){
  105.            
  106.             $username = $_POST['username'];
  107.             $email = $_POST['email'];
  108.             $password = $_POST['password'];
  109.             $first_name = $_POST['first_name'];
  110.             $last_name = $_POST['last_name'];
  111.             $update = "UPDATE `users`
  112.                     SET `username`=".$username.",
  113.                     `password`=".$password.",
  114.                     `email`=".$email.",
  115.                     `first_name`=".$first_name.",
  116.                     `last_name`=".$last_name."
  117.                     WHERE `id`={$num}";
  118.             $done_update = mysqli_query($conn,$update);
  119.             if($done_update == true){
  120.             echo "<script type='text/javascript'>alert('User Edited!');</script>";
  121.             }
  122.             else{
  123.             echo "<script type='text/javascript'>alert('User not Edited!')</script>";
  124.             }
  125.         }
  126.        
  127.        
  128.        
  129.        
  130.        
  131.        
  132.         if(isset($_POST['delete'])){
  133.             $delete = "DELETE FROM `users` WHERE `id`= {$num}";
  134.             $done_delete = mysqli_query($conn,$delete);
  135.             if(isset($done_delete)){
  136.             echo "<script type='text/javascript'>alert('User Deleted!'); location.href='edit_user.php';</script>";
  137.             }
  138.             else{
  139.             echo "<script type='text/javascript'>alert('User not Deleted!')</script>";
  140.             }
  141.         }
  142.        
  143.     }
  144. //<?php echo $row['last_name'];}
  145.    
  146. ?>
  147. </table>
  148. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
  149. integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
  150. crossorigin="anonymous">
  151. <style>
  152.  
  153. #loading-img{
  154. display:none;
  155. }
  156.  
  157. .response_msg{
  158. margin-top:10px;
  159. font-size:13px;
  160. background:#E5D669;
  161. color:#ffffff;
  162. width:250px;
  163. padding:3px;
  164. display:none;
  165. }
  166.  
  167. </style>
  168. <div class="container">
  169. <div class="row">
  170.  
  171. <div class="col-md-8">
  172. <h1>Edit user</h1>
  173. <form name="contact-form" action="" method="post" id="contact-form">
  174. <div>
  175. <label for="username">Username</label>
  176. <input type="text" class="form-control" name="username" placeholder="username" required>
  177. </div>
  178. <div>
  179. <label for="password">Password</label>
  180. <input type="text" class="form-control" name="password" placeholder="password" required>
  181. </div>
  182. <div >  
  183. <label for="email">Email</label>
  184. <input type="email" class="form-control" name="email" placeholder="Email" required>
  185. </div>
  186. <div >
  187. <label for="first_name">First Name</label>
  188. <input type="text" class="form-control" name="first_name" placeholder="first_name" required>
  189. </div>
  190. <div>
  191. <label for="last_name">Last Name</label>
  192. <input type="text" class="form-control" name="last_name" placeholder="last_name"  required>
  193. </div>
  194. </form><!--value=""-->
  195. <!--<script>class="form-group"
  196. function update() {
  197.     var x;
  198.     if(confirm("Update successful") == true){
  199.         x="update";
  200.     }
  201. }
  202. </script>-->
  203. <script>
  204. $(document).ready(function(){
  205. $("#contact-form").on("submit",function(e){
  206. e.preventDefault();
  207. if($("#contact-form [name='from_who']").val() === '')
  208. {
  209. $("#contact-form [name='from_who']").css("border","1px solid red");
  210. }
  211. else if ($("#contact-form [name='email']").val() === '')
  212. {
  213. $("#contact-form [name='email']").css("border","1px solid red");
  214. }
  215. else
  216. {
  217. $("#loading-img").css("display","block");
  218. var sendData = $( this ).serialize();
  219. $.ajax({
  220. type: "POST",
  221. url: "contact_form_message.php",
  222. data: sendData,
  223. success: function(data){
  224. $("#loading-img").css("display","none");
  225. $(".response_msg").text(data);
  226. $(".response_msg").slideDown().fadeOut(3000);
  227. $("#contact-form").find("input[type=text], input[type=email], textarea").val("");
  228. }
  229.  
  230. });
  231. }
  232. });
  233.  
  234. $("#contact-form input").blur(function(){
  235. var checkValue = $(this).val();
  236. if(checkValue != '')
  237. {
  238. $(this).css("border","1px solid #eeeeee");
  239. }
  240. });
  241. });
  242. </script>
  243. <br>
  244. <form method="post">
  245. <a href="edit_user.php">
  246. <input type="button" class="btn btn-primary" value="Refresh"/>
  247. </a>
  248. <a href="admin.php">
  249. <input type="button" class="btn btn-primary" value="Back"/>
  250. </a>
  251. <a href="create.php">
  252. <input type="button" class="btn btn-primary" value="Add User"/>
  253. </a>
  254. <a>
  255. <button type="submit" class="btn btn-primary" name="submit" value="Edit User">Update</button>
  256. </a>
  257. <a href="edit_user.php">
  258. <input type="submit" class="btn btn-primary" name="delete" value="Delete User"/>
  259. </a>
  260. </form>
  261. </body>
  262. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement