[英]I want to use the INSERT statement to insert values that come from the SELECT statements in PHP
I want to use the INSERT statement to insert values that come from the SELECT statements in PHP我想使用 INSERT 语句在 PHP 中插入来自 SELECT 语句的值
the table of student is not get the data学生表未获取数据
$sql = "INSERT INTO student(academic_major, promo, user_id) VALUES (?, ?, (?));";
$stmtt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmtt, $sql)){
header("Location: add_student_forum.php?error=sqlerrorstudent");
exit();
}else{
$id = "SELECT id FROM user WHERE email = '$email'";
mysqli_stmt_bind_param($stmtt, "sss", $academic_major, $promo, $id);
mysqli_stmt_execute($stmtt);
header("Location: add_student_forum.php?signup=success".$id);
exit();
}
when i execute it shows me this header header("Location: add_student_forum.php?signup=success".$id);当我执行它时,它会显示这个 header 标头(“位置:add_student_forum.php?signup=success”.$id); in the url and i dont know why the table is empty after在 url 中,我不知道为什么桌子之后是空的
You don't bind SQL as a parameter.您不将 SQL 绑定为参数。 Bind the data as parameter and put the SELECT SQL in the prepared statement SQL将数据绑定为参数,将 SELECT SQL 放入准备好的语句 SQL
$sql = "INSERT INTO student(academic_major, promo, user_id) VALUES (?, ?, SELECT id FROM user WHERE email = ?);";
$stmtt = mysqli_stmt_init($conn);
mysqli_stmt_prepare($stmtt, $sql);
mysqli_stmt_bind_param($stmtt, "sss", $academic_major, $promo, $email);
mysqli_stmt_execute($stmtt);
header("Location: add_student_forum.php?signup=success".$id);
exit();
Make sure you have mysqli error reporting enabled.确保您启用了 mysqli 错误报告。 How to get the error message in MySQLi?如何获取 MySQLi 中的错误信息?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.