Page 1 of 1

PHP and pass through queries

Posted: Tue Apr 20, 2010 2:20 pm
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

Re: PHP and pass through queries

Posted: Tue Apr 20, 2010 5:16 pm
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.

Re: PHP and pass through queries

Posted: Wed Apr 21, 2010 2:58 am
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

Re: PHP and pass through queries

Posted: Mon Jun 21, 2010 6:34 am
by longbo43
Thanks for the replies and sorry for the delay in replying.

Used the mysql_insert_id() and this worked a treat.

Cheers