Advertisement
Guest User

Untitled

a guest
May 20th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.59 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_once ("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.             }
  30.  
  31.             if (isset ($_POST["student"])) {
  32.                 $student = trim($_POST["student"]);
  33.                 $query = "SELECT * FROM attempts WHERE ((student_id = '$student') or (first_name = '$student'))";
  34.                 $result = mysqli_query($conn, $query);
  35.             }
  36.  
  37.             if (isset ($_POST["hund"])) {
  38.                 $query = "SELECT * FROM attempts WHERE ((score = 5) && (attempts = 1))";
  39.                 $result = mysqli_query($conn, $query);
  40.             }
  41.  
  42.             if (isset ($_POST["fif"])) {
  43.                 $query = "SELECT * FROM attempts WHERE ((score = 2) && (attempts = 3))";
  44.                 $result = mysqli_query($conn, $query);
  45.             }
  46.  
  47.             if (isset ($_POST["delete"])) {
  48.                 $student = trim($_POST["delete"]);
  49.                 $query = "DELETE FROM attempts WHERE student_id = '$student'";
  50.                 $result = mysqli_query($conn, $query);
  51.             }
  52.  
  53.             if (isset ($_POST["score"])) {
  54.                 $student = $_POST["score"];
  55.                 $change = $_POST["changeattempt"];
  56.                 $value = $_POST["value"];
  57.                 $query = "UPDATE attempts SET score = '$value' WHERE attempts = '$change' and student_id = '$student'";
  58.                 $result = mysqli_query($conn, $query);
  59.             }
  60.  
  61.             if (!$result) {
  62.                 echo "<p>Somethinng is wrong with ", $query, "</p>";
  63.             }else {
  64.                 echo "<table border=\"1\">\n";
  65.                 echo "<tr>\n "
  66.                     ."<th scope=\"col\">First Name</th>\n "
  67.                     ."<th scope=\"col\">Last Name</th>\n "
  68.                     ."<th scope=\"col\">Student ID</th>\n "
  69.                     ."<th scope=\"col\">Attempts</th>\n "
  70.                     ."<th scope=\"col\">Score</th>\n "
  71.                     ."</tr>\n ";
  72.                     //retrive current record point by the record pointer
  73.                 while ($row = mysqli_fetch_assoc($result)) {
  74.                     echo "<tr>\n ";
  75.                     echo "<td>", $row["first_name"], "</td>\n ";
  76.                     echo "<td>", $row["last_name"], "</td>\n ";
  77.                     echo "<td>", $row["student_id"], "</td>\n ";
  78.                     echo "<td>", $row["attempts"], "</td>\n ";
  79.                     echo "<td>", $row["score"], "</td>\n ";
  80.                     echo "</tr>\n ";
  81.                 }
  82.                 }
  83.             echo "</table>\n ";
  84.         }
  85.     ?>
  86.  
  87.  
  88. </body>
  89. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement