简体   繁体   English

我想使用 INSERT 语句在 PHP 中插入来自 SELECT 语句的值

[英]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.

相关问题 将多个Select语句插入Insert语句 - Multiple Select statements into an Insert statement 我想在单个 INSERT 语句中将包含两个数组(字符串)的多个值插入到 php 中的 mysql 表中 - I want to insert multiple values which includes two arrays(of strings) in a single INSERT statement into a table of mysql in php PostgreSQL中的insert…select语句将php中的插入值与select语句组合在一起 - insert…select statement in postgresql combining inserted values from php with a select statement 在php中我的INSERT INTO SELECT FROM语句正确吗? - Is my INSERT INTO SELECT FROM statement in php correct? 如何使用 implode() 在 PHP 中使用准备好的语句将多个整数插入 IN 语句? - How do I use implode() to insert multiple integers into IN statement using prepared statements in PHP? 如何在后续的MULTIPLE插入语句(在PHP和MYSQL中)中使用mysql_insert_id的最新插入中的值? - How do I use the value from the latest insert using mysql_insert_id in subsequent MULTIPLE insert statements (in PHP and MYSQL)? 如何通过SELECT和INSERT INTO SQL语句使用PHP变量 - How to use PHP variables with SELECT and INSERT INTO SQL Statements 在插入中插入增量值... select 语句 mysql - insert incremental values in an insert ... select statement mysql PHP / MySQL-Mysqli-预备语句-循环时在另一个select语句中运行多个insert语句? - PHP/MySQL - Mysqli - Prepared Statements - Run multiple insert statements within another select statement while loop? 我想将表单中的数据插入表中,然后从另一个表中选择另一个数据并使用PHP插入到第三张表中 - I want to insert a data from a form into a table, and select another data from another table and insert into third table using PHP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM