如何检查重复但不刷新页面?PHP

  • 本文关键字:PHP 刷新 何检查 php mysql
  • 更新时间 :
  • 英文 :


这是我的编码。我想检查一下重复的数据。如果存在重复数据,则会弹出警报,但一旦我单击"确定",它将转到一个空白页面,无法返回表单。如何使它弹出警报而不刷新页面?

<?php
include "db_con.php";
if (isset($_POST['edit_appt'])) {
$appointment_id = $_POST['appointment_id'];
$job_number = $_POST['job_number'];
$technician_id = $_POST['technician_id'];
$appointment_date = $_POST['appointment_date'];
$appointment_time = $_POST['appointment_time'];
$query = "SELECT * FROM appointment WHERE technician_id='$technician_id' && appointment_date='$appointment_date' && appointment_time='$appointment_time';";
$result = mysqli_query($con, $query);
if (mysqli_num_rows($result) == 1) {
echo "<script>alert('Technician is unavailable! Please select another technician!!')</script>";
} else {
$query2 = "UPDATE appointment SET technician_id='$technician_id' WHERE appointment_id='$appointment_id'";
$result2 = mysqli_query($con, $query2);
if ($result2) {
$query1 = "UPDATE reparation SET technician_id='$technician_id',notification_status='unread' WHERE job_number='$job_number'";
$result1 = mysqli_query($con, $query1);
if ($result1) {
echo "<script>alert('Updated!')</script>";
echo "<script>window.open('admin_appt.php','_self')</script>";
}
}
}
}

其中一个解决方案是执行javascript重定向。

尝试更改

echo "<script>alert('Technician is unavailable! Please select another technician!!')</script>";

echo "<script>alert('Technician is unavailable! Please select another technician!!'); history.go(-1);</script>";

还请考虑使用参数化的prepared语句来避免SQL注入,正如Strawberry所提到的。(您可以参考以下内容:准备好的语句如何防止SQL注入攻击?(

最新更新