Monday, 19 August 2013

my quiz appliation with jquery ajax php everything is working fine but after i receive the data from php not working

my quiz appliation with jquery ajax php everything is working fine but
after i receive the data from php not working

my main page
<html>
<head>
<!--<link href="css/style.css" type="text/css" rel="stylesheet"> -->
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"
type="text/javascript"></script>
<script src="jquery/myscript.js"></script>
</head>
<body>
<?php
$dbconnect=mysqli_connect('localhost','root','','quiz')or die("Error
Connecting to database");
$query="select * from question_answer ";
$result=mysqli_query($dbconnect,$query);
?>
<form method="get" action="">
<div id="container">
<?php
while($rows=mysqli_fetch_array($result))
{
echo '<div class="QA">';
echo '<h1>'.$rows['question'].'</h1>'.'<br/>';
echo '<input type="radio" class="check"
name="'.$rows['id'].'"
value="A">'.$rows['option1'].'</input>';
echo '<input type="radio" class="check"
name="'.$rows['id'].'"
value="B">'.$rows['option2'].'</input>';
echo '<input type="radio" class="check"
name="'.$rows['id'].'"
value="C">'.$rows['option3'].'</input>';
echo '<input type="radio" class="check"
name="'.$rows['id'].'"
value="D">'.$rows['option4'].'</input>';
echo '<br/>';
echo '<div class="report"></div>';
echo'</div>';
}
?>
</div>
</form>
</body>
</html>
and this is my script where I have ajax passing value and php returning
the data when I alert the data received from php its working but the
following line after that where i have my jquery to display the result and
slideUP is not working
$(document).ready(function(){
var clickedvalue,qid;
$("input:radio").change(function(){
clickedvalue=$(this).val();
qid=$(this).attr('name');
$.get('checkanswer.php',{'clickedvalue':clickedvalue,'qid':qid},function(data){
$(this).parent("div.QA").find(".report").html(data);
$(this).slideUp();
});
});
});
and this the php file
<?php
$questionid=$_GET['qid'];
$answer=$_GET['clickedvalue'];
$dbconnect=mysqli_connect('localhost','root','','quiz')or die("Error
Connecting to database");
$query="select answer from question_answer where id=$questionid";
$result=mysqli_query($dbconnect,$query);
while($rows=mysqli_fetch_array($result))
{
$dbanswer=$rows['answer'];
}
if($dbanswer==$answer)
{
echo "Correct Answer";
}
else{
echo "Incorrect Answer";
}
?>

No comments:

Post a Comment