I have online examination portal, in which a user selects an answer and clicks next. At this point I make an AJAX call.
With each AJAX call I insert one row into the database. I'm storing marks as floats.
It should store either 1 or -0.25, but sometimes it stores 0, and I can't find the problem.
Here is my code:
Jquery Code:
var questin = $("#ques"+next).val(); var secin = $("#sect"+next).val(); $.ajax({ data:{ques:questin,answ:n,sec:secin}, method:'post', async:false, url:'result.php', success:function(data){ } });
PHP Code:
<?php include("action/db.php"); session_start(); $ques_id = $_REQUEST['ques']; $mark = (float) $_REQUEST['answ']; $sec = $_REQUEST['sec']; $exam_date_id = $_SESSION['ex_da']; $use_id = $_SESSION['uid']; $run->db_open(); $query2 = mysql_query("SELECT * FROM useranswers WHERE question_id='$ques_id' AND user_id='$use_id'"); $no = mysql_num_rows($query2); if($no==0){ $date = date("Y:m:d:h:m:s"); $query1 = mysql_query("INSERT INTO useranswers VALUES ('','$exam_date_id','$use_id','$ques_id',0,'$sec','$mark','0','0','$date')"); }else{ $query1 = mysql_query("UPDATE useranswers SET mark='$mark' WHERE question_id='$ques_id'"); } $run->db_close(); ?>