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; ";

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 ,.

You can't INSERT and SELECT on the same action on PHP.

But you meant INSERT the SELECTED RESULT than all you need is to do the following

INSERT INTO `Table-Destination`
SELECT * FROM `Table-Source` ...