dongzhan8620 2015-01-16 08:24
浏览 7

插入两个相关表格

tbl_account
username | password | status

tbl_data
username | name | address | phone

how can i insert data into both tables with php? I tried with query

INSERT INTO tbl_account(username, password, status)
OUTPUT INSERTED.'bobo', 'Bobo Ali','Markt St. 26', '0979877'
INTO tbl_data(username, name, address, phone)
VALUES  ('bobo','bobo123','manager');

but it doesn't work at all. The process is success but the table is remain empty.

  • 写回答

4条回答 默认 最新

  • douxuan3095 2015-01-16 08:29
    关注

    You will need seperate queries for inserting the same data into multiple tables.

    If you are having trouble with that, the process is simple:

    1. Use the query to insert the data into the first table
    2. Free the last result using mysqli_free_result() (or mysql_free_result() if you are using the MySQL API.
    3. Reuse the same query you used in step 1. to insert the data into the second table

    Code:

    <?php
    
    INSERT INTO tbl_account(username, password, status)
    VALUES ('bobo', 'Bobo Ali','Markt St. 26', '0979877');
    
    // Free the result here
    
    INSERT INTO tbl_data(username, name, address, phone)
    VALUES  ('bobo','bobo123','manager');
    
    // Free the result again, so you can use the query again if needed
    
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭