Advertisement
Guest User

Untitled

a guest
May 20th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.77 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="utf-8" />
  5.     <meta name="description" content="quiz managment" />
  6.     <meta name="keywords" content="PHP, MySql, assignment3" />
  7.     <title>Mangement</title>
  8. </head>
  9. <body>
  10.     <h1>Quiz Results database search</h1>
  11.     <?php
  12.         require ("settings.php"); //connection info
  13.  
  14.         $conn = @mysqli_connect($host,
  15.                 $user,
  16.                 $pwd,
  17.                 $sql_db
  18.         );
  19.  
  20.         if (!$conn) {
  21.             echo "<p>Database connection failure</p>";
  22.         }
  23.         //checks if connection is succesful and displays a error message if connection isnt successful
  24.         else {
  25.             $sql_table = "attempts";
  26.             if (isset ($_POST["all"])) {
  27.                 $query = "SELECT * FROM attempts";
  28.                 $result = mysqli_query($conn, $query);
  29.                 var_dump($result);
  30.             }
  31.             else { echo "<p>all</p>";}
  32.             if (isset ($_POST["student"])) {
  33.                 $student = $_POST["student"];
  34.                 $query = "SELECT * FROM attempts WHERE student_id like '$student' or first_name like '$student'";
  35.                 $result = mysqli_query($conn, $query);
  36.                 var_dump($result);
  37.             }
  38.             else {echo "<p>student</p>";}
  39.             if (isset ($_POST["hund"])) {
  40.                 $query = "SELECT * FROM attempts WHERE score=5 and attempts=1";
  41.                 $result = mysqli_query($conn, $query);
  42.                 var_dump($result);
  43.             }
  44.             else {  echo "<p>hundo</p>";}
  45.             if (isset ($_POST["fif"])) {
  46.                 $query = "SELECT * FROM attempts WHERE score<=2 and attempts=3";
  47.                 $result = mysqli_query($conn, $query);
  48.                 var_dump($result);
  49.             }
  50.             else {echo "<p>fifty</p>";}
  51.             if (isset ($_POST["delete"])) {
  52.                 $student = $_POST["delete"];
  53.                 $query = "DELETE FROM attempts WHERE student_id like '$student'";
  54.             }
  55.             else {echo "<p>delete</p>";}
  56.             if (isset ($_POST["score"])) {
  57.                 $student = $_POST["score"];
  58.                 $change = $_POST["changeattempt"];
  59.                 $value = $_POST["value"];
  60.                 $query = "UPDATE attempts SET score = '$value' WHERE attempts = '$change' and student_id = '$student'";
  61.             }
  62.             else {echo "<p>scorechange</p>";}
  63.             if (!$result) {
  64.                 echo "<p>Somethinng is wrong with ", $query, "</p>";
  65.             }
  66.             else {
  67.                 echo "<table border=\"1\">\n";
  68.                 echo "<tr>\n "
  69.                     ."<th scope=\"col\">First Name</th>\n "
  70.                     ."<th scope=\"col\">Last Name</th>\n "
  71.                     ."<th scope=\"col\">Student ID</th>\n "
  72.                     ."<th scope=\"col\">Attempt</th>\n "
  73.                     ."<th scope=\"col\">Score</th>\n "
  74.                     ."</tr>\n ";
  75.                     //retrive current record point by the record pointer
  76.                 while ($row = mysqli_fetch_assoc($result)) {
  77.                     echo "<tr>\n ";
  78.                     echo "<td>", $row["first_name"], "</td>\n ";
  79.                     echo "<td>", $row["last_name"], "</td>\n ";
  80.                     echo "<td>", $row["student_id"], "</td>\n ";
  81.                     echo "<td>", $row["attempts"], "</td>\n ";
  82.                     echo "<td>", $row["score"], "</td>\n ";
  83.                     echo "</tr>\n ";
  84.                 }
  85.             }
  86.             echo "</table>\n ";
  87.             }
  88.                    
  89.     ?>
  90.  
  91.  
  92. </body>
  93. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement