代碼裏面我有一個JavaScript確認框,我有一些MySQL的插入一些條件要執行查詢代碼。這就是我的代碼的樣子:如何執行JavaScript確認框
<?php
$id = $_POST['id'];
$name= $_POST['name'];
$query = mysql_query("select * from table where id='$id'");
$count = mysql_num_rows($query);
if($count!=0)
{
?>
<script type="text/javascript">
if (confirm("This seems to be Duplicate. Do you want to continue ?") == true)
{
//Execute/Insert into table as how it is given below
}
else
{
//Dont execute/insert into table but close the window
}
</script>
<?php
}
else
{
$queryinsert = mysql_query("INSERT INTO table(id,name) VALUES('$id','$name')");
}
?>
我想你需要做一些關於AJAX的研究,可能是JQuery – RiggsFolly
你能分享更多的代碼嗎?你如何得到這個片段?你會需要調用Ajax調用PHP腳本確認後,或者你可以做一個location.href =「myscript.php ignoreDuplicate = 1?」;然後使用它像'如果($計數!= 0 &&(!isset($ _ GET [ 'ignoreDuplicate'] || $ _GET [ 'ignoreDuplicate'] == 0))){...}' 這的如果你不使用任何框架,當然應該這樣做。 –