for($c=1;$c<=$num;$c++)
{
$row=mysql_fetch_array(mysql_query("SELECT * FROM `$quiztitle` WHERE id=$c"));
if($row['answer']==$_POST['answer'][$c]) // NOT WORKING
{
echo "correct";
echo "<br>";
}
else
{
echo "incorrect";
echo "<br>";
}
}
on the line where it says "NOT WORKING", the index [$c] does not get the value from the loop. but when i specify it and change it to $_POST['answer1'], it is working. what is the correct syntax for this?
Based on your note, it looks like you want:
$_POST["answer$c"]
Correct is:
if ($row['answer'] == $_POST['answer' . $c]) {
....
}
Try this.
for($c=1;$c<=$num;$c++) {
$row=mysql_fetch_array(mysql_query("SELECT * FROM `$quiztitle` WHERE id=$c"));
if($row['answer']==$_POST['answer'.$c]) // NOT WORKING
{
echo "correct";
echo "<br>";
}
else
{
echo "incorrect";
echo "<br>";
}
}
You're treating 'answer' as an array here, looking for an index within.
You want to concatenate the value.
if($row['answer']==$_POST["answer{$c}'])