代码里面我有一个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))){...}' 这的如果你不使用任何框架,当然应该这样做。 –