我正在尝试通过两个 ID 来删除一条记录。第一个传递的 ID 是要删除的患者的历史记录的 ID。第二个 ID 是历史记录表的患者外键的主 ID。一旦我删除了患者的历史记录,它将重定向回该患者的个人资料。
这是我的表操作中的代码:
<td><a class="text-danger" onClick="return confirm('Are you sure you want to clear this record?')" href="clear_records.php?id=<?php print $rows4['id'];?>?p_id=<?php print $rows5['p_id']; ?>"><i class="fa fa-times text-danger"></i>Clear</a></td>
这是 clear_records.php
中的代码<?php
include "../config.php";
$id = $_REQUEST['id'];
$p_id = $_REQUEST['p_id'];
// sql to delete a record
$sql = "DELETE FROM nutritional_records WHERE id=$id";
if ($conn->query($sql) === TRUE) {
header("location: preschooler_profile.php?p_id=$p_id");
} else {
echo "Error Clearing record: " . $conn->error;
}
$conn->close();
?>
这是错误:
Error Clearing record: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?p_id=00023' at line 1
这是我的网址:
http://localhost/NutriCare/admin/clear_records.php?id=8?p_id=00023
寻求帮助。 提前致谢。
最佳答案
您的 URL
应该是这样的-
http://localhost/NutriCare/admin/ClearRecords.php?id=8&p_id=00023
URL 中的第一个参数后应该有一个与号 (&) 而不是问号。
关于PHP 在 URL 中传递两个 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45779253/