php and mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Ben11858
Forum Newbie
Posts: 16
Joined: Sat Nov 28, 2009 11:27 am

php and mysql

Post 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.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: php and mysql

Post 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?
Ben11858
Forum Newbie
Posts: 16
Joined: Sat Nov 28, 2009 11:27 am

Re: php and mysql

Post 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
Post Reply