简体   繁体   English

从一个表中选择并插入另一个表

[英]Select from a table and insert into another table

1- I have inserted products in the table cart (and it works) 1-我已将产品插入餐车(并且可以使用)
2- I identify if is a new or old customer(and it works) 2-我确定是新客户还是旧客户(有效)
3- I insert the new customer in the table customers or I update the new info of an existed customer. 3-我将新客户插入表客户中,或更新现有客户的新信息。 (and it works) I write here the code simplified. (并且有效)我在这里编写了简化的代码。

I suppose that now I need to insert in the table cart, row customer_id, the id just created in the table customers (I mean the session id of table customers) How can I do that? 我想现在我需要在表格购物车中的第customer_id行中插入表格客户中刚刚创建的ID(我的意思是表格客户的会话ID),该怎么办?

if(isset($_POST["continue"])){
    mysql_query("INSERT INTO customers (name)
    VALUES ('$_POST[name]')") 
    or die("error:".mysql_error());
    header("Location:step4.php");   

}else if (isset($_POST["update"])) {
    mysql_query("UPDATE customers 
                 SET name='$_POST[name]'
                 WHERE mail='$_SESSION[mail]'")
    or die("error:".mysql_error());
    header("Location:step4.php?updated");   
}

I tried and it does not work this: 我试过了,这不起作用:

mysql_query("INSERT INTO cart (customer_id)
             SELECT'$_SESSION['id']' 
             FROM customers")

使用此处记录的mysql_insert_id()http : //php.net/manual/zh/function.mysql-insert-id.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MySQL从表中选择并插入另一个 - Mysql select from a table and insert into another 从db表1中选择数据并将其插入到php中的另一个db表2中 - Select data from db table 1 and insert it into another db table 2 in php PHP-SQL如何从表中选择ID并插入到另一个表中? - PHP - SQL how to select ids from table and insert into another table? 从一个表中选择所有数据并将其插入到另一个表中 - Select all data from a table and insert it to another table Select 来自一个表的 ID 并使用 while 循环插入到另一个表中 - Select ID from one table and insert in another table with while loop 如何插入表数据并从另一个表中选择? - How to insert into a table data and select from another table? 我想将表单中的数据插入表中,然后从另一个表中选择另一个数据并使用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 有什么有效的方法可以从一个表中全选并插入另一个表中 - Is there any efficient way to select all from one table and insert in another 从表中选择,并插入到另一个数据 - 数据乘以-SQL - Select from table, and insert data to another - Multiply data -SQL 插入表中,因为select * from table不起作用 - insert into table as select * from table does not work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM