Reputation: 317
Hi how can I insert the same ID as the account being created with this statement into a table which is called layouts using this mysql statement?
$q = $dbc -> prepare("INSERT INTO accounts (email, password, salt, username, gender, loginIP, shrapnel, joined) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
$q -> execute(array($_POST['email'], hash('sha512', 'jooosjdsakjdsn' . $_POST['password'] . md5($random)), md5($random), $_POST['username'], $_POST['gender'], $_SERVER['REMOTE_ADDR'], $random, date('Y-m-d : H:i:s')));
Is it possible with a join? The ID is an auto increment field in the table accounts.
Upvotes: 0
Views: 115
Reputation: 1393
you will have to add some sql to your script like this insert into layouts(accountsid,.......) VALUES(LAST_INSERT_ID(), ....).
Note: if the accounts table also has an identity column and you insert into it multiple times than you have to keep the LAST_INSERT_ID() for the master table into a separate variable otherwise starting with the second insert into the accounts table the LAST_INSERT_ID() function will return the IDs of the accounts table
Upvotes: 1
Reputation: 5919
You could try using LAST_INSERT_ID()
in another query immediately afterwards.
Upvotes: 2