Thursday, 19 September 2013

PHP adding to sessions

PHP adding to sessions

I am making an online quiz, in this quiz, one question is asked at a time.
If the answer is correct, I want to add that point, to the total score
earned. I want the $_SESSION to show how many points the user has earned
so far. The code I have so far is this:
$sql = "SELECT * FROM quiz_questions WHERE Question='$question' AND
Answer='$answer'";
$result = mysql_query($sql);
$num_rows = mysql_num_rows($result);
if ($num_rows != 0){
$score++;
$total_score += $score;
session_start();
$_SESSION['score'] = $total_score;
} else {
echo "Incorrect";
}
}
I already have $score equal to 0 to start in the beginning of the code.
Thank you in advance for all your help!

No comments:

Post a Comment