gpt4 book ai didi

php - 使用准备好的语句插入外键

转载 作者:行者123 更新时间:2023-11-29 17:56:38 25 4
gpt4 key购买 nike

我想使用 table_complaints 中的预准备语句插入外键 resident_id。

这是我的照片:

enter image description here

我还在 View 页面中得到了 $ides = $_POST["resident_id"];

enter image description here

$servername = "localhost";
$username = "root";
$password = "";
$database = "myDb";

$conn = mysqli_connect($servername, $username, $password, $database);
if(!$conn){
die("Connection Failed: " . mysqli_connect_error());
}

if(isset($_POST["submits"])){
$comp_text = $_POST["comp"];
$complaints = $_POST["complaints"];
$ides =$_POST["resident_id"];

$statementi = mysqli_stmt_init($conn);
mysqli_stmt_prepare($statementi, "INSERT INTO table_complaint (nature_of_complaints, status)
VALUES (?, ?) WHERE resident_id = ?");
mysqli_stmt_bind_param($statementi, "ssi", $comp_text, $complaints);

mysqli_stmt_execute($statementi);

mysqli_stmt_close($statementi);
}
mysqli_close($conn);

最佳答案

您的插入查询不正确。

你可以使用这个:

INSERT INTO table_complaint (resident_id,nature_of_complaints, status) VALUES (?,?,?)

然后绑定(bind)参数:

mysqli_stmt_bind_param($statementi, "iss", $ides,$comp_text, $complaints);

关于php - 使用准备好的语句插入外键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48758311/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com