Advertisement
Guest User

No UPDATE

a guest
Aug 31st, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. The login_update.php code:
  2.  
  3.  
  4. <?php include "db.php";?>
  5. <?php include "functions.php"; ?>
  6.  
  7. <?php if(isset($_POST['submit'])){
  8.  
  9. $username = $_POST['username'];
  10. $password = $_POST['password'];
  11. $id = $_POST['id'];
  12.  
  13. $query = "UPDATE users SET ";
  14. $query .= "username = '$username', ";
  15. $query .= "password = '$password' ";
  16. $query .= "WHERE id = $id"; //fara '' pt ca id in baza de date e integer
  17.  
  18. $result = mysqli_query($connection, $querry);
  19.  
  20. if(!$result) {
  21.  
  22. die('Nu a trecut querry!'. mysqli_error($connection));
  23. }
  24.  
  25. }
  26.  
  27. ?>
  28. <!DOCTYPE html>
  29. <html lang="en">
  30. <head>
  31. <meta charset="UTF-8">
  32. <title>Document</title>
  33. <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
  34. <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
  35. </head>
  36. <body>
  37.  
  38. <div class="container">
  39.  
  40. <div class="col-sm-6">
  41. <form action = "login_create.php" method = "post">
  42.  
  43. <div class="form-group">
  44. <label for="username"><b>Username</b></label>
  45. <input type="text" class="form-control" name = "username">
  46. </div>
  47.  
  48. <div class="form-group">
  49. <label for="password"><b>Password</b></label>
  50. <input type="password" class="form-control" name = "password">
  51. </div>
  52.  
  53. <div class="form-group">
  54. <select name="id" id="">
  55.  
  56.  
  57. <?php
  58. showAllData();
  59. ?>
  60.  
  61.  
  62. </select>
  63. </div>
  64.  
  65. <div class="form-group">
  66. <label for="submit"></label>
  67. <input type="submit" class="btn-primary" name = "submit" value = "UPDATE">
  68. </div>
  69.  
  70. </form>
  71. </div>
  72.  
  73. </div>
  74.  
  75.  
  76. </body>
  77. </html>
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92. The db.php code:
  93.  
  94. <?php
  95.  
  96. $connection = mysqli_connect('localhost', 'root', '', 'loginapp');
  97.  
  98. if(!$connection) {
  99.  
  100. die ('No database connection');
  101. }
  102.  
  103.  
  104. ?>
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114. The functions.php code:
  115.  
  116.  
  117. <?php include 'db.php'; ?>
  118.  
  119. <?php
  120.  
  121.  
  122. function showAllData(){
  123.  
  124. global $connection;
  125.  
  126. $query = "SELECT * FROM users";
  127. $result = mysqli_query($connection, $query);
  128.  
  129. if(!$result){
  130. die ("Query failed!" . mysqli_error());}
  131.  
  132. while($row = mysqli_fetch_assoc($result)){
  133.  
  134. $id = $row['id'];
  135.  
  136. echo "<option value='$id'>$id</option>";
  137.  
  138. }
  139.  
  140. }
  141.  
  142. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement