vikiesakki Posted December 21, 2015 Share Posted December 21, 2015 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: <?phpinclude("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();?> Quote Link to comment https://forums.phpfreaks.com/topic/299919-ajax-call-sometimes-stores-the-wrong-value/ Share on other sites More sharing options...
requinix Posted December 21, 2015 Share Posted December 21, 2015 That would mean the value of "n" from the Javascript would be 0 or something that cannot be converted to a number. Right? So what is the actual value of n during those requests? Or alternatively, what does the AJAX request look like in terms of the form data submitted (which you should be able to get directly from the browser). Quote Link to comment https://forums.phpfreaks.com/topic/299919-ajax-call-sometimes-stores-the-wrong-value/#findComment-1528363 Share on other sites More sharing options...
vikiesakki Posted December 22, 2015 Author Share Posted December 22, 2015 1 or -0.25 is the actual value of 'n'. My problem is 5days its working normal but now its not working. i don't know what could be the problem. Quote Link to comment https://forums.phpfreaks.com/topic/299919-ajax-call-sometimes-stores-the-wrong-value/#findComment-1528431 Share on other sites More sharing options...
requinix Posted December 22, 2015 Share Posted December 22, 2015 So you're saying you tried making a bunch of requests, watching in the browser as each request gets sent, until you got one of them to insert 0 for a question? And the value of "n" in the browser (or the value of "answ" in the request data) is always 1 or -0.25? Do you have email set up? Try something as simple as if ($mark != 1 && $mark != -0.25) { mail("yourself@example.com", "mark={$mark}", var_dump($_REQUEST, true), "From: yoursendingaccount@example.com"); }Then you'll get an email every time $mark doesn't have the right value, and it will include all the form data that was sent. And you say it's a recent development? That must mean something has changed recently. Were there any changes to the site? Did your host upgrade PHP versions or change other configuration? Quote Link to comment https://forums.phpfreaks.com/topic/299919-ajax-call-sometimes-stores-the-wrong-value/#findComment-1528434 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.