【发布时间】:2017-01-11 03:06:57
【问题描述】:
我想将数据保存到数据库中,但在此之前我必须检查名称条件。如果名称可用,它将显示确认弹出窗口(我使用甜蜜警报)。我已经尝试过这段代码,但它无法执行保存数据的功能。谁能帮帮我?
代码:
$name = $_POST['name'];
$cekname = mysql_query("select * from data_alumni where name='$name'");
$jumlahnama = mysql_num_rows($cekname);
if ($jumlahname > 0) {
echo '<script>swal({ title: "Are you sure?", text: "name is available, continue save?", type: "warning", showCancelButton: true, confirmButtonColor:"#DD6B55", confirmButtonText: "Yes, delete it!", closeOnConfirm: false }, function(){' . savedata($nama) . '});</script>';
} else {
#other function
}
【问题讨论】:
-
PHP 可以将 Javascript 代码回显到发送到客户端的页面中,就像您正在做的那样,但是 Javascript 代码不能直接调用服务器上的 PHP 代码,因为它是在客户端上运行的,而不是服务器。
-
哦好的丹,谢谢你的问题..解决了因为我使用 jquery ajax :)
标签: javascript php sweetalert