Advertisement
Guest User

Untitled

a guest
Aug 20th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.56 KB | None | 0 0
  1. <?php include 'server.php';
  2.  
  3. //fetch the record
  4. if (isset($_GET['edit'])) {
  5. $id = $_GET['edit'];
  6. $edit_state = true;
  7. $rec = mysqli_query($db, "SELECT * FROM users where id=$id");
  8. $record = mysqli_fetch_array($rec);
  9. $username = $record['username'];
  10. $password = $record['password'];
  11. $lastname = $record['lastname'];
  12. $firstname = $record['firstname'];
  13. $sample = "tangina";
  14. $sample2 = "gago";
  15. $sample3 = "okay";
  16. $id = $record['id'];
  17. }
  18. if (isset($_GET['edit1'])) {
  19. $id = $_GET['edit1'];
  20. $edit_state = true;
  21. $rec = mysqli_query($db, "SELECT * FROM users where id=$id");
  22. $record = mysqli_fetch_array($rec);
  23. $username = $record['username'];
  24. $password = $record['password'];
  25. $lastname = $record['lastname'];
  26. $firstname = $record['firstname'];
  27. $sample = "first";
  28. $sample2 = "second";
  29. $sample3 = "thrid";
  30. $id = $record['id'];
  31. }
  32.  
  33. ?>
  34. <!DOCTYPE html>
  35. <html>
  36. <head>
  37. <title>Account Settings</title>
  38. <link rel="stylesheet" type="text/css" href="css/acc-style.css">
  39. </head>
  40. <body>
  41. <?php if (isset($_SESSION['msg'])): ?>
  42. <div class="msg">
  43. <?php
  44. echo $_SESSION['msg'];
  45. unset($_SESSION['msg']);
  46. ?>
  47. </div>
  48.  
  49. <?php endif ?>
  50. <table>
  51. <thead>
  52. <tr>
  53. <th>Username</th>
  54. <th>Password</th>
  55. <th>Lastname</th>
  56. <th>Firstname</th>
  57.  
  58. <th colspan="2">Action</th>
  59. </tr>
  60. </thead>
  61. <tbody>
  62. <?php while ($row = mysqli_fetch_array($results)) { ?>
  63. <tr>
  64. <td><?php echo $row['username']; ?></td>
  65. <td><?php echo $row['password']; ?></td>
  66. <td><?php echo $row['lastname']; ?></td>
  67. <td><?php echo $row['firstname']; ?></td>
  68. <td>
  69. <a href="index.php?edit=<?php echo $row['id']; ?>" class = "edit_btn" onclick="myFunction()">Edit</a>
  70. </td>
  71. <td>
  72. <a href="index.php?edit1=<?php echo $row['id']; ?>" class="delete_btn">Delete</a>
  73. </td>
  74. </tr>
  75. <?php } ?>
  76.  
  77. </tbody>
  78. </table>
  79. <form method="post" action="server.php">
  80. <input type="hidden" name="text_id" value="<?php echo $id; ?>">
  81. <div class="input-group">
  82. <label>Username</label>
  83. <input type="text" name="text_username" value="<?php echo $sample; ?>" required>
  84. </div>
  85. <div class="input-group">
  86. <label>Password</label>
  87. <input type="text" name="text_password" value="<?php echo $sample2; ?>" required>
  88. </div>
  89. <div class="input-group">
  90. <label>Lastname</label>
  91. <input type="text" name="text_lastname" value="<?php echo $sample3; ?>" required>
  92. </div>
  93. <div class="input-group">
  94. <label>Firstname</label>
  95. <input type="text" name="text_firstname" value="<?php echo $sample; ?>" required>
  96. </div>
  97. <div class="input-group">
  98. <?php if ($edit_state == false): ?>
  99. <button type="submit" name="save" class="btn" onclick="myFunction()">Save</button>
  100. <?php else: ?>
  101. <button type="submit" name="update" class="btn">Update</button>
  102. <?php endif ?>
  103. </div>
  104. </form>
  105.  
  106.  
  107. <!--dashboard-->
  108. <div id="header">
  109. <div class="logo"><a href="#">Pacific Sky Beach Resort Admin Panel <span></span></a></div>
  110. </div>
  111. <div id="container">
  112. <div class="sidebar">
  113. <ul id="nav">
  114. <li><a href="dashboard.php">Dashboard</a></li>
  115. <li><a href="cms.php">CMS</a></li>
  116. <li><a class="selected" href="acc-settings.php">Account Settings</a></li>
  117. <li><a href="#">Reservation/Cancelation</a></li>
  118. <li><a href="login.php">Logout</a></li>
  119.  
  120. </ul>
  121. </div>
  122. <script>
  123. function myFunction() {
  124. var txt;
  125. var r = confirm("Press a button!");
  126. if (r == true) {
  127. txt = if (isset($_POST['edit'])) {
  128. $username = $_POST['text_username'];
  129. $password = $_POST['text_password'];
  130. $lastname = $_POST['text_lastname'];
  131. $firstname = $_POST['text_firstname'];
  132. $sample = "tanginamo";
  133. $id = $_POST['text_id'];
  134.  
  135. mysqli_query($db, "UPDATE users SET username = '$username', password = '$password', lastname = '$lastname', firstname = '$firstname' where id=$id");
  136. $_SESSION['msg'] = "Account Updated!";
  137. header('location: index.php');
  138. } else {
  139. txt = "You pressed Cancel!";
  140. }
  141. document.getElementById("demo").innerHTML = txt;
  142. }
  143. </script>
  144. </body>
  145. </html>
  146.  
  147. <?php
  148.  
  149. session_start();
  150.  
  151. $username = "";
  152. $password = "";
  153. $lastname = "";
  154. $firstname = "";
  155. $sample = "";
  156. $sample2 = "";
  157. $sample3 = "";
  158. $id = 0;
  159. $edit_state = false;
  160.  
  161.  
  162. //connect to the database
  163. $db = mysqli_connect('localhost', 'root', '', 'login');
  164.  
  165. //update
  166. if (isset($_POST['edit'])) {
  167. $username = $_POST['text_username'];
  168. $password = $_POST['text_password'];
  169. $lastname = $_POST['text_lastname'];
  170. $firstname = $_POST['text_firstname'];
  171. $sample = "tanginamo";
  172. $id = $_POST['text_id'];
  173.  
  174. mysqli_query($db, "UPDATE users SET username = '$username', password = '$password', lastname = '$lastname', firstname = '$firstname' where id=$id");
  175. $_SESSION['msg'] = "Account Updated!";
  176. header('location: index.php');
  177. }
  178.  
  179. //retrieve records
  180. $results = mysqli_query($db, "SELECT * FROM users");
  181.  
  182. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement