Im trying to run the php file but its giving the empty variables, it quiz website in which user answer i am tring to compare the user response with database value but giving no results
here is the answer.php that calls the function:
<?php
require("functions.php");
$ss=answer($_POST);
?>
here is function.php file
<?php
include('dbConnect.php');
?>
<?php
function answer($data){
// creating query to get category id
$sql="select * from category";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result)){
$cat=$row['cat_id'];
}
// another query to select table and compare values
$response="select q_id, ans from questions where cat_id='$cat'" ;
$right_answer=0;
$wrong_answer=0;
$unanswered=0;
$result = mysql_query($response);
while($qust=mysql_fetch_array($result)){
if($qust['ans']==$_POST[$row['q_id']]){
$right_answer++;
} else if($_POST[$row['q_id']]=="no_attempt"){
$unanswered++;
} else {
$wrong_answer++;
}
}
}
echo "right_answer : ". $right_answer."<br>";
echo "wrong_answer : ". $wrong_answer."<br>";
echo "unanswered : ". $unanswered."<br>";
?>