Search code examples
phpmysqlinsert-updatelastinsertid

Using an insert id from first of three queries in php


I want to store the data from several curl calls to an initial table, but last insert id is inserting wrong info

Query 1 inserts data into table

table1

   id name      email      valuereturn
   1   val     [email protected]       0

I then post data 3 times to my system and log it

table2

    id  name    system  valuereturn
    1   val      5       0
    2   val      0       0
    3   val      0       0

the max value returned from my system i want to update table 1

update table1 
set valuereturn = '5' 
where id = LAST_INSERT_ID()

does not work because last insert id is 3 from table2, how can I use something like last_insert_id(Table1)?

i want to update my


Solution

  • Well, you can't. You have to retrieve and remember it in a PHP variable.

    Or go for Saharsh's solution and remember it in a MySQL variable.