我想使用table_complaints中的预准备语句插入外键resident_id。
这是我的照片:
我也会在视图页面中看到$ides = $_POST["resident_id"];
$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);
答案 0 :(得分:0)
您的插入查询不正确。
您可以使用:
INSERT INTO table_complaint (resident_id,nature_of_complaints, status) VALUES (?,?,?)
然后绑定参数:
mysqli_stmt_bind_param($statementi, "iss", $ides,$comp_text, $complaints);