PHP 在 URL 中传递两个 id

标签 php mysql

我正在尝试通过两个 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/

相关文章:

PHP 长轮询,无需过多的数据库访问

mysql - 正确查询以获取日期时间

javascript - 如何使用反引号在 node.js 中编写多行 MySQL 查询?

PHP MySql执行SP时查询错误

php - 客户端同时连接多个服务器,通过连接在所有服务器执行一段代码

java - 使用具有字符串的额外列将数据从一个 Mysql 表传输到另一个表

mysql - 第一次出现其他字段=值时更新字段?

mysql - #1062 - key '19' 的重复条目 'PRIMARY'

javascript - jquery-ui tooltip() 函数无法识别

php - 阿拉伯语语言转换 php 到 mysql