Forum Moderators: open

Message Too Old, No Replies

Which Record?

         

webfoo

7:03 pm on Jun 27, 2008 (gmt 0)

10+ Year Member



I posted this over in PHP, but no answer. I'm kinda in a hurry.

PAGE A: a PHP file that updates a database with inital user info (ip address, date, etc). Prints out a form, which submits to Page B.

PAGE B: another PHP file that's supposed to write more info to the same reccord as Page A.

Using PHP or AJAX, how can I capture which record id Page A writes to, so that Page B can write to the same reccord.

rocknbil

11:19 pm on Jun 27, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Part of the process of page A should be to grab the id or other unique handle of the newly inserted record, then set a variable in memory to write out a hidden field to include in the submit to page B.

Insert into db (fields) value (values);
select id from db order by id desc limit 1;

Use result to set $id.
<input type="hidden" name="id" value="$id">

Page B would use this field to update the record, make sure you error trap in case something goes wrong and the value is blank.

This is a "shortcut" way of getting last ID, not all that efficient, but it works, see recent discussion [webmasterworld.com]. I think mysql has a last_record function (or similar,) I've just stuck with this method. Yeah, lazy . . . .

webfoo

11:35 pm on Jun 27, 2008 (gmt 0)

10+ Year Member



Wow, I can't beleive I overlooked such a simple solution. I'll try this out and see how it works! Thanks!

It's not a high traffic page so it doesn't have to be too efficient.

Cheers,
webfoo