How do I check the selected radio button value with the value stored in a database field? Code is below:
index.php:
dfdfdffdfdfdfdf
question.php
$_POST['answer'];
$totalCorrect = 0;
if ($_POST == 'CorrectAnswer') { $totalCorrect++;}
echo "$totalCorrect questions correct";
I want to pass the answer chosen to check it with the database to see if it matches the value of CorrectAnswer
and edit the score accordingly.
You missed to access the 'answer' index when accessing $_POST
. Use:
if ($_POST['answer'] == 'CorrectAnswer') { $totalCorrect++;}
instead.
try something like this:
if ($_POST['answer'] == 'CorrectAnswer') { $totalCorrect++;}
N.B. you don't need the method
attribute on your submit button as this is already declared in the <form>
tag.