I have done scripts like this before but cannot figure out for the life of me why I can't get results.
I am running a query to get a certain student's quiz results from all attempts and print one after the other in a simple table for now. The student is designated by an email address. I need results from all of the rows containing this particular email. The issue I think I am having is that when I use "WHERE" and specify an email address that exists many times in the table it isn't storing the variable correctly. Here is code below that I cannot get working right.
When I try to print these variables as a test to see if they are working I get nothing. No errors either. I have checked all names, spellings, and capitalization about 5 times. Thanks for looking at it.
Code that I believe to be in question:
$QuizQuery = mysql_query("SELECT * FROM Quiz_Results WHERE Email = '".$_SESSION['UserEmail']."' AND Quiz_Name = 'M1'")
or die(mysql_error());
$i=1;
while ($QuizResults = mysql_fetch_array($QuizQuery)){
$UserEmail = $QuizResults['Email'];
$Score = $QuizResults['Score'];
$Date = $QuizResults['Date_Taken'];
echo "<table width='650' border='1'><tr><td>";
echo "Attempt #".$i."<br></td><td>Score: ".$Score."</td><td>";
if($QuizResults['Pass'] == "PASSED"){
echo "Passed";
}
else {
echo "Failed";
}
echo "</td><td>Date Taken: ".$Date."</td></tr></table>";
$i++;
}
The page loads with no data displayed. Here is the full code. Thanks for looking.
mysql data fields = Id, Quiz_Id (PRI, AUTOINC), Quiz_Name, Score, Pass, Date_Taken
Full Code:
<?
include('db.php');
session_set_cookie_params(1200);
session_start();
if(ISSET($_POST['Email'])){
$_SESSION['UserEmail'] = $_POST['Email'];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<link href="ptdetxquiz.css" type="text/css" rel="stylesheet" />
</head>
<style type="text/css">
body {
font: 100% Verdana, Arial, Helvetica, sans-serif;
background-color: #fff;
margin: 0; /* it's good practice to zero the margin and padding of the body element to account for differing browser defaults */
padding: 0;
text-align: center; /* this centers the container in IE 5* browsers. The text is then set to the left aligned default in the #container selector */
color: #000000;
}
</style>
<body>
<div class="oneColFixCtr">
<div id="container">
<img src='images/backgroundtop.jpg' />
<div id='container2' align='center'>
<img src="images/quizrecordsbanner.jpg" />
<?
//Change DB Selected
mysql_connect($host, $dbusername, $password);
mysql_select_db($TxQuizdb);
$VerifyQuery = mysql_query("SELECT Email, Stud_First_Name, Stud_Last_Name FROM ".$RegTable." WHERE Email = '".$_SESSION['UserEmail']."' ")
or die(mysql_error());
$Verify = mysql_fetch_array($VerifyQuery);
$_SESSION['StudFirstName'] = $Verify['Stud_First_Name'];
$_SESSION['StudLastName'] = $Verify['Stud_Last_Name'];
if(($Verify)){
echo "<br><br><br><div id='summarytitle'>".$_SESSION['StudFirstName']." ".$_SESSION['StudLastName']."'s Quiz Records:</div>";
echo "Module 1 Quizzes<br>";
$QuizQuery = mysql_query("SELECT * FROM Quiz_Results WHERE Email = '".$_SESSION['UserEmail']."' AND Quiz_Name = 'M1'")
or die(mysql_error());
$i=1;
while ($QuizResults = mysql_fetch_array($QuizQuery)){
$UserEmail = $QuizResults['Email'];
$Score = $QuizResults['Score'];
$Date = $QuizResults['Date_Taken'];
echo "<table width='650' border='1'><tr><td>";
echo "Attempt #".$i."<br></td><td>Score: ".$Score."</td><td>";
if($QuizResults['Pass'] == "PASSED"){
echo "Passed";
}
else {
echo "Failed";
}
echo "</td><td>Date Taken: ".$Date."</td></tr></table>";
$i++;
}
print_r($UserEmail);
echo $i;
print_r($Score);
print_r($QuizResults['Email']);
//echo $QuizResults['Email'];
}
else{
echo "E-mail address not found. Please re-enter your e-mail.<br><form action='myquizzes.php' method='post' />
<input type='text' size='40' name='Email' /><br />
<input type='submit' name='submit' value='View Quiz Records' />";
}
?>
</div>
<img src="images/backgroundbottom.jpg" />
</div>
</body>
</html>