Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title>Questions</title>
  5. </head>
  6.  
  7. <body>
  8.  
  9. <form method="post" action="deleteQuestions.php" enctype="multipart/form-data">
  10.  
  11. <style>
  12. td {
  13. text-align: left;
  14. }
  15. </style>
  16.  
  17. Select rank :
  18. <select name="type" id="type" onchange="this.form.submit()">
  19.  
  20. <?php if(isset($_POST['type']))
  21. { ?>
  22. <option value="1" <?php echo($_POST['type']==1?"selected":"");?>>SSgt</option>
  23.  
  24. <option value="2" <?php echo($_POST['type']==2?"selected":"");?>>TSgt</option>
  25. <option value="3" <?php echo($_POST['type']==3?"selected":"");?>>MSgt</option>
  26. </select>
  27. <br><br>
  28. <?php
  29. }
  30. else
  31. {
  32. ?>
  33. <option value="1">SSgt</option>
  34. <option value="2">TSgt</option>
  35. <option value="3">MSgt</option>
  36. </select>
  37. <br><br>
  38. <?php
  39. }
  40. ?>
  41.  
  42. <table id="example" style="width:50%">
  43. <tr>
  44. <th><font size="5">Questions</font></th>
  45. </tr>
  46.  
  47. <?php
  48.  
  49. ini_set('display_errors', 1);
  50. error_reporting(1);
  51. ini_set('error_reporting', E_ALL);
  52.  
  53. $dbh = new PDO('mysql:host=17475.54;dbname=a', 'airman', 'a5');
  54.  
  55.  
  56. if(isset($_POST['type']))
  57. {
  58. $stmt = $dbh->prepare("SELECT * FROM questions where type = :type");
  59. $stmt->bindParam("type", $_POST['type']);
  60. $stmt->execute();
  61. $results = $stmt->fetchall(PDO::FETCH_ASSOC);
  62.  
  63. }
  64. else{
  65. $stmt = $dbh->prepare("SELECT * FROM questions");
  66. $stmt->execute();
  67. $results = $stmt->fetchall(PDO::FETCH_ASSOC);
  68.  
  69. }
  70.  
  71. foreach($results as $que)
  72.  
  73. {
  74. ?>
  75. <tr>
  76. <td><?php echo $que['question'];?></td>
  77. <td><input type="submit" id="<?php echo $chapter['id']?>" name="action" value="Delete<?php echo $que['id']?>">
  78.  
  79. <input type="hidden" name="id" value="<?php echo $que['id']?>" />
  80.  
  81. </tr>
  82. <?php
  83. }
  84. ?>
  85. </table>
  86.  
  87. </body>
  88.  
  89. <?php
  90.  
  91.  
  92.  
  93. if(isset($_POST['action'])) {
  94.  
  95. ini_set('display_errors', 1);
  96. error_reporting(1);
  97. ini_set('error_reporting', E_ALL);
  98.  
  99.  
  100. $stmt = $dbh->prepare("DELETE FROM `questions` WHERE `id`= " . $_POST['id']);
  101.  
  102. $stmt->execute();
  103. $result = $stmt->fetch(PDO::FETCH_ASSOC);
  104.  
  105. if(count($result) > 0)
  106. {
  107. echo 'row deleted';
  108. ?>
  109.  
  110. <?php
  111. }
  112. else{
  113. echo 'row could not delete';
  114. }
  115. }
  116. else{
  117. echo 'not deleted';
  118. }
  119.  
  120. ?>
  121. </form>
  122. </html>
  123. <?php
  124. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement