Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. <?php
  2. require 'dbh.inc.php';
  3.  
  4.  
  5. // Check if its a get request and if so, display the form
  6. if (isset($_GET['edit_list'])) {
  7. // Set the param variable
  8. $listNameRatings = $_GET['edit_list'];
  9.  
  10. mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
  11.  
  12. // Define query
  13. $stmt = $mysqli->prepare("SELECT * FROM ratings WHERE listNameRatings=?");
  14. // Bind the parameter
  15. $stmt->bind_param("s", $listNameRatings);
  16. // Execute the query
  17. $stmt->execute();
  18. // Fetch the result in an array
  19. $resultArray = $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
  20. // Check if the resulted array has data, else exit with a message
  21. if(!$resultArray){
  22. echo "No results";
  23. exit;
  24. } else {
  25. // Show the form
  26. ?>
  27. <form action="/" method="post" class="form-width-md">
  28. <div class="form-row">
  29. <?php foreach($resultArray as $row): ?>
  30. <div class="form-group col-md-3">
  31. <input class="form-control form-control-sm" type="text" name="idRatings" value="<?= $row['idRatings'] ?>">
  32. </div>
  33. <div class="form-group col-md-3">
  34. <input class="form-control form-control-sm" type="text" name="listNameRatings" value="<?= $row['listNameRatings'] ?>">
  35. </div>
  36. <div class="form-group col-md-3">
  37. <input class="form-control form-control-sm" type="text" name="itemRatings" value="<?= $row['itemRatings'] ?>">
  38. </div>
  39. <div class="form-group col-md-2">
  40. <input class="form-control form-control-sm" type="number" name="ratingRatings" value="<?= $row['ratingRatings'] ?>">
  41. </div>
  42. <?php endforeach; ?>
  43. <button class="btn btn-success btn-sm" type="submit" name="btn-update" id="btn-update">Update</button>
  44. <a class="btn btn-secondary btn-sm ml-3" role="button" href="yourlists.php">Cancel</a>
  45. </div>
  46. </form>
  47. <?php
  48. }
  49. }
  50.  
  51.  
  52. // Check if its a POST request
  53.  
  54. if (isset($_POST['btn-update'])) {
  55.  
  56. $idRatings = $_POST['idRatings'];
  57. $listNameRatings = $_POST['listNameRatings'];
  58. $itemRatings = $_POST['itemRatings'];
  59. $ratingRatings = $_POST['ratingRatings'];
  60.  
  61.  
  62. $update = "UPDATE ratings SET listNameRatings=?, itemRatings=?, ratingRatings=? WHERE idRatings=?";
  63. mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
  64.  
  65. // Define query
  66. $stmt = $mysqli->prepare("SELECT * FROM ratings WHERE listNameRatings=?");
  67. // Bind the parameter
  68. $stmt->bind_param("sssi", $listNameRatings, $itemRatings, $ratingRatings, $idRatings);
  69. // Execute the query
  70. $stmt->execute();
  71.  
  72. mysqli_stmt_close($stmt);
  73. mysqli_close($conn);
  74.  
  75. // Redirect
  76. header("Location: ../yourlists.php?edit=success");
  77. exit();
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement