PHP and pass through queries

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
longbo43
Forum Newbie
Posts: 10
Joined: Tue Apr 20, 2010 2:33 am

PHP and pass through queries

Post by longbo43 »

Hi guys,

Am new at PHP so please bear with me if this is a stupid question but can PHP run a pass through query.

If so please can someone help me with this. I have a query with calculates the last number of an autonumber field within a table. I can change the type of query to a passthrough query and then would like to call this number and use it in my PHP form by adding 1to this number and this will give me the next id number I need to be assigned to the submitted form

Please help if this can be done and sorry for wasting your time if it can't.

Cheers
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP and pass through queries

Post by requinix »

No, don't do that.

If you're inserting new data into a table you shouldn't care about the ID until after the insert happened. You can look it up easily and reliably at that point.
User avatar
JAY6390
Forum Newbie
Posts: 20
Joined: Sat Apr 17, 2010 6:51 am
Location: UK

Re: PHP and pass through queries

Post by JAY6390 »

Yup, assigning the id before the the data is submitted could cause all sorts of problems - for example, if you have 3 people connect to the page at the same time, all three will be given the next id which means they would update the table and replace each others data. You need mysql_insert_id() once you've run your insert query
longbo43
Forum Newbie
Posts: 10
Joined: Tue Apr 20, 2010 2:33 am

Re: PHP and pass through queries

Post by longbo43 »

Thanks for the replies and sorry for the delay in replying.

Used the mysql_insert_id() and this worked a treat.

Cheers
Post Reply