시작 시간과 종료 시간 값이 mysql에 저장되는 웹 기반 스톱워치를 만들려고했습니다. 스톱워치는 자바 스크립트에서 만들어지며 jquery를 사용하여 MySQL에 저장합니다. 문제는 내가 스톱워치를 클릭 할 때마다 값이 mysql에 두 번 삽입되는 반면 한 번만 삽입되어야한다는 것입니다. 내 insert.php 코드의 여기Jquery가 mysql에 두 번 삽입됩니다.
function stopTimers() {
clearInterval(_myTimer_ms);
clearInterval(_myTimer_s);
clearInterval(_myTimer_m);
clearInterval(_myTimer_h);
$(document).ready(function(){
//Get the input data using the post method when Push into mysql is clicked .. we pull it using the id fields of ID, Name and Email respectively...
$("#stop").click(function(){
//Get values of the input fields and store it into the 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 the $.post() method to call insert.php file.. this is the 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 the data given by the insert.php file
}
);
return false;
});
});
}
과 :이 두 번 삽입 왜
<?php
//Configure and Connect to the Databse
$con = mysql_connect("localhost","diki","diki");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("diki", $con);
//Pull data from 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 into mysql
$query=mysql_query("INSERT INTO diki02(cell,machine,hour,tmin,sec,mssec,date,Stoptime) VALUES('$cell','$machine','$hour','$tmin','$sec','$mssec','$my_date',NOW())");
if($query){
echo "Data for $cell and $machine inserted successfully!";
}
else{ echo "An error occurred!"; }
?>
아직도 파악 ,, 사람이 지금 같은 문제가 발생 여기 내 코드는입니까?
THankss
코드에서 어떤 일이 일어나고 있는지 잘 모르겠습니다. 이'stopTimers' 함수는 무엇입니까? 전화가 어디 있습니까? 왜 그것은'$ (document) .ready'를 포함합니까? 'click' 핸들러를'# stop'에 여러 번 바인드하는 이상한 일을하는 것이 가능합니다. – freakish
stopTimers 함수는 스톱워치를 멈추고 mysql 데이터베이스에 데이터 (cell, machine, hour, tmin, sec, mssec 등)를 저장합니다. – placeb0