|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi everybody,
Who can help me to fix a problem. I want to join two tables. TABLE_A Aid int; //auto increment name varchar; TABLE_B Bid int; //same id as Aid Author varchar; if ($voegtoe) { // name of button in form //add a record ID Aid auto increment $sql_A = "INSERT INTO TABLE_A (naam) VALUES ('$name')"; mysql_query($sql_A); //Tryin' to get the last ID from TABLE_A $result_A = mysql_query("SELECT Aid FROM TABLE_A"); $objectid= mysql_query($result_A); //Tryin' to use Aid From TABLE_A $sql_B = "INSERT INTO TABEL B (Bid, author) VALUES ('$objectid', '$author')"; mysql_query($sql_B); } TABLE_B is not getting the ID from TABLE_A, Why?? Regards, Vin@ic |
|
#2
|
|||
|
|||
|
Because you are not getting the last id from table a. Your select will return the first id (actually it returns all but you're only getting the result for the first one.) There's a easier, safer way to do this. Check the php manual for the function mysql_insert_id(). This will do what you want.
Rod |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > PHP Development > Insert into 2 tables?? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|