php - Jquery inserting twice to mysql -


i have been trying create web-based stopwatch in value of start time , stop time stored mysql. stopwatch created in javascript, , use jquery store mysql. problem whenever click 'stop'on stopwatch, value inserted twice in mysql while should inserted once. here's code snippet :

function stoptimers() {   clearinterval(_mytimer_ms);   clearinterval(_mytimer_s);   clearinterval(_mytimer_m);   clearinterval(_mytimer_h);    $(document).ready(function(){     //get input data using post method when push mysql clicked .. pull using id fields of id, name , email respectively...     $("#stop").click(function(){       //get values of input fields , store variables.       var cell=$("#cell").val();       var machine=$("#machine").val();       var hour=$("#hour").val();       var tmin=$("#tmin").val();       var sec=$("#sec").val();       var mssec=$("#mssec").val();            //use $.post() method call insert.php file.. ajax request       $.post('insert.php', {cell: cell,machine: machine,hour: hour,tmin : tmin,sec: sec,mssec: mssec},         function(data){           $("#message").html(data);           $("#message").hide();           $("#message").fadein(100); //fade in data given insert.php file         }       );       return false;     });   });     } 

and here's insert.php code :

<?php //configure , connect databse  $con = mysql_connect("localhost","diki","diki");  if (!$con) {  die('could not connect: ' . mysql_error());  }  mysql_select_db("diki", $con);  //pull data home.php front-end page  $my_date = date("y-m-d h:i:s");  //$my_time =  $cell=$_post['cell'];  $machine=$_post['machine'];  $hour=$_post['hour'];  $tmin=$_post['tmin'];  $sec=$_post['sec'];  $mssec=$_post['mssec'];   //insert data mysql $query=mysql_query("insert diki02(cell,machine,hour,tmin,sec,mssec,date,stoptime) values('$cell','$machine','$hour','$tmin','$sec','$mssec','$my_date',now())"); if($query){ echo "data $cell , $machine inserted successfully!"; } else{ echo "an error occurred!"; } ?> 

still figuring out why it's inserted twice,, ever encountered same problem ?

thankss

try script block

'removed $(document).ready(function(){}); ' block

//get input data using post method when push mysql clicked .. pull using id fields of id, name , email respectively...                 $("#stop").click(function () {                      clearinterval(_mytimer_ms);                     clearinterval(_mytimer_s);                     clearinterval(_mytimer_m);                     clearinterval(_mytimer_h);                     //get values of input fields , store variables.                     var cell = $("#cell").val();                     var machine = $("#machine").val();                     var hour = $("#hour").val();                     var tmin = $("#tmin").val();                     var sec = $("#sec").val();                     var mssec = $("#mssec").val();                        //use $.post() method call insert.php file.. ajax request                     $.post('insert.php', { cell: cell, machine: machine, hour: hour, tmin: tmin, sec: sec, mssec: mssec },                     function (data) {                         $("#message").html(data);                         $("#message").hide();                         $("#message").fadein(100); //fade in data given insert.php file                     });                     return false;                 }); 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -