Advertisement
Guest User

Untitled

a guest
Nov 15th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <form method = "post" action = "get.php">
  6. <input type="submit" value="Next" onclick = 'document.getElementById("id").value++; ' />
  7. <input type="text" name="id" id = "id" />
  8. </form>
  9.  
  10. <?php
  11.  
  12. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  13. $servername = "localhost";
  14. $username = "root";
  15. $password = "";
  16. $dbname = "gin446";
  17.  
  18. // Create connection
  19. $conn = new mysqli($servername, $username, $password, $dbname);
  20. // Check connection
  21. if ($conn->connect_error) {
  22. die("Connection failed: " . $conn->connect_error);
  23. }
  24. $id= $_POST['id'];
  25. echo $id;
  26. $sql = "SELECT `question`,`choice1`,`choice2`,`choice3`,`choice4` FROM quiz where id = $id";
  27. $result = $conn->query($sql);
  28.  
  29. if ($result->num_rows > 0) {
  30. // output data of each row
  31. while($row = $result->fetch_assoc()) {
  32. echo " ".$row["question"]." <br> ";
  33.  
  34. for ( $i = 1 ; $i < 5 ; $i++) {
  35. if ($row["choice".$i.""] != null )
  36. echo "<input type='radio'/> " . $row["choice".$i.""]. "<br>";
  37. }
  38.  
  39. }
  40. } else {
  41. echo "0 results";
  42. }
  43. $conn->close();
  44.  
  45. }
  46. ?>
  47. </form>
  48. </body>
  49. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement