I am using the following with a quiz I am making, it checks the table to see if the user has already posted the answer to the question and isn’t hammering the submit button, the problem I am having is its not posting the info to the database for some odd reason. If I take out the if statement and the first database looking and just post the data it works fine, but when I check the result of the first query first, it doesn’t appear to work, even if the user hasn’t submitted an answer yet.
<?php
$quizID = $_GET['quiz'];
$userID = $_GET['user'];
$quizselectanswer = $_POST['quizselectanswer'];
$cf_created = date("y/m/d");
$questionID = $_POST['questionID'];
// Check to see if user answered question already
$result = mysql_query("SELECT questionID,userID FROM itsnb_chronoforms_data_answerquiz WHERE questionID='$questionID' AND userID='$userID' LIMIT 1") or die(mysql_error());
while($row = mysql_fetch_array($result))
{
if (empty($row))
{
mysql_query("INSERT INTO itsnb_chronoforms_data_answerquiz (cf_created, questionID,quizselectanswer,quizID, userID)
VALUES ('$cf_created', '$questionID', '$quizselectanswer', '$quizID','$userID')")
or
die(mysql_error());
}else{
}
}
?>
My database looks like this itsnb_chronoforms_data_answerquiz cf_id, cf_uid, cf_created, cf_modified ,cf_ipaddress ,cf_user_id ,questionID, quizselectanswer, quizID ,userID.
Try like this it may help you