Forum Moderators: coopster

Message Too Old, No Replies

Can't I select and insert data into the same table in PHP?

         

Habtom

5:36 am on Mar 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi,

Can't I select and insert data into the same table in PHP?

$SQL = "INSERT INTO c (name, prices, prices2, del, loc) SELECT D.name, D.prices, D.prices2, D.del, 7777777 FROM c D WHERE D.loc = '". $_POST['txtCopyFrom'] ."'";

Hab

Vastio

5:50 am on Mar 26, 2006 (gmt 0)

10+ Year Member



I believe you need an UPDATE instead of an INSERT

DrDoc

8:05 am on Mar 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sure you can ... I do that all the time. Do you get an error?

coopster

11:06 pm on Mar 26, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



... unless that table is running on a MySQL server prior to MySQL 4.0.14. The target table of the INSERT statement cannot appear in the FROM clause of the SELECT part of the query. This limitation is lifted in 4.0.14.