dongying9756 2014-12-31 11:33
浏览 20
已采纳

php mysql插入值并选择[关闭]

how to insert variable and select in php

table1 1,2,3,4,5 table2 1,2,3,4

i want to insert table1 from table2 and table1.5 add variable (sorry idont speak english very well :) ) query:

"INSERT INTO `table1` (`table1`.`5`, `1`, `2`, `3`, `4`, ) 
 $variable, select `1`, `2`, `2`, `3`, `4` from `table2` where  `table2`.`3`=3; ";
  • 写回答

2条回答 默认 最新

  • douli2063 2014-12-31 12:17
    关注

    In your query syntax error is there. syntax is told you by @Orel Eraki...

    So your SQL should be:

    $sql="INSERT INTO `table1` (`1`, `2`, `3`, `4`, `5`) 
     SELECT `1`, `2`, `3`, `4`, '$variable' FROM `table2` WHERE `table2`.`3`=3;";
    

    I have changed the sequence of columns in INSERT list.


    Errors:

    1) $variable should be after SELECT (in select's column list), not before it.

    2) in SELECT list you have written column named as 2 two times... no of columns should be same as INSERT, and including $variable total goes to 6. So I removed one column 2.

    3) in INSERT after column named as 4 you have a ,.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?