Page 1 of 1

php and mysql

Posted: Sun Nov 29, 2009 6:12 am
by Ben11858
This might be in the wrong place, but its a bit of both mysql and php..

I have a 2 tables with different data with a primary key which needs to be the same for both tables like a reference key.

Now I have a page that takes form detail and enters it into both tables. Now the probelm is, they reference key is set as auto increment so that it ads one everytime someone enters details into the form and I need that reference key to be passed to the next page so I can use that to update things from there.

Its possible that the same data will be enter into the form, so if I created a select statement to check for a row with those particular details, in time 2 results might come back meaning that I have 2 reference keys when I can only have 1.

Is there a way with php to create the insert statement and when that insert is done, to pass the id reference number for that insert row back to the page so I have that unique number for that row as its possible to get dupilcate rows.

Sorry if its confusing, I'm struggling to get my head around it as it is...

Any help would be appreciated.

Re: php and mysql

Posted: Sun Nov 29, 2009 6:37 am
by requinix
If I told you that MySQL had a LAST_INSERT_ID function that returned the auto-increment value used in the previous INSERT query, do you think you could check the manual for an appropriately-named PHP function?

Re: php and mysql

Posted: Sun Nov 29, 2009 7:47 am
by Ben11858
Ah yes, I stumbled across that very same peice of code when i was looking for something else. So I'm trying that.. Cheers