Forum Moderators: coopster

Message Too Old, No Replies

A race to the finish.

Two commands executing at the same time?

         

theriddla1019

8:59 pm on Aug 9, 2004 (gmt 0)

10+ Year Member



Not sure if this is the right forum but since im using php imna give it a go in here. This is kind of a trailer from another post but the situation has changed a little.
I have a page with an iframe, when the user submits the parent page the iframe is submitted via javascript. Just sends the page a force submit. No more javascript is used. The i-frame is submitted onclick of the submit button of the parent page so the iframe information is updated via php to the database a split second before the action of the parent page sends its information to its own update page.
Heres the 411:
The iframe page is using "insert (table)" then pulling the autoincrement via mysql_insert_id() (and yes its set to type int not bigint) and ive also tried the internal function "SELECT LAST_INSERT_ID()" and get the same results. Then the parent page "Sets" the values to update the same record and uses the last id to find the last updated record.
The Results:
Both functions are pulling the ID for the previous update (hence not to get confused, the one before the last update i performed) its like its not seeing the last update or somehow the parent page's update script is running before the iframe page's update script.
I Guess My Question:
Is there anyway to pause the execution of the parent page's form action with php? or is there a better way to do this that im overlooking?

coopster

9:18 pm on Aug 9, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



How about using a session variable or a cookie to store the value of the LAST_INSERT_ID() rather than trying to time things correctly? Or, better yet, why not allow the script processing occur in either one or the other form actions, but not both?

theriddla1019

10:03 pm on Aug 9, 2004 (gmt 0)

10+ Year Member



I am updating a session variable on the page that is "updating"
$_SESSION(lastID) = MYSQL_INSERT_ID();
and using the variable on the parent page that is "setting" where id = '" . $_SESSION(lastID) . "'"
but it seems the second page being called (the "setting" page) is running b4 the first page that was called(the "updating" page).
Sorry forgot to include that tidbit in my original post.

theriddla1019

10:05 pm on Aug 9, 2004 (gmt 0)

10+ Year Member



And as for the script to process in one page or another, theres so many variables on each page it would be a nightmare to post em all over. Which was what my original post was about (not this thread) but I could never get an answer. (If there was an easier way to post all the variable over or pull them out of the iframe to the parent page. So i could submit)

coopster

12:08 am on Aug 10, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Oh, I didn't realize when you stated *session* in that other post [webmasterworld.com], that you really meant a PHP session. Let's think about this. If you have one main page, and you start a session, then you have an IFRAME, and that starts a session, you are going to have two different sessions, correct? This is going to lead to problems.

theriddla1019

1:16 pm on Aug 10, 2004 (gmt 0)

10+ Year Member



ok i understand where your coming from but i have to start the(a) session on the iframe page to set the session variable correct? is there a way to add to the current open session with another page? guess ill try a cookie...also SELECT LAST_INSERT_ID() AS lastID; im running from the page that is saving(setting) last. is this the correct placement for this function or is it supposed to be on the page that performs the insert like mysql_insert_id? am i supposed to run query's on this statement like any other select statement i use?
$Query = "SELECT LAST_INSERT_ID() AS lastID";
$Result = mysql_query($Query, $Link);
is there anything else i have to do with it to get it to work?...i find a lot of sites with information on what it does and the theory behind it and situations where it wont work etc but nothing on how to actually use it in different situations. ... ok i think im done for now :)
Thanx,
Adam

coopster

7:08 pm on Aug 11, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



i have to start the(a) session on the iframe page to set the session variable correct?

Correct. Anywhere you want to set session variables you must start a session first.

is there a way to add to the current open session with another page?

I suppose you could use javascript to write HTML <form> variables back and forth in the frames and then handle the data server-side from one form's action or the other.

also SELECT LAST_INSERT_ID() AS lastID; im running from the page that is saving(setting) last. is this the correct placement for this function or is it supposed to be on the page that performs the insert like mysql_insert_id?

The script that performs the INSERT is the connection that should handle the LAST_INSERT_ID(). It is a per-connection feature.

am i supposed to run query's on this statement like any other select statement i use?
$Query = "SELECT LAST_INSERT_ID() AS lastID";
$Result = mysql_query($Query, $Link);
is there anything else i have to do with it to get it to work?

You've got it. Or, if you are going to use it in an INSERT or UPDATE statement, you don't even have to select it first, you can simply use it...

INSERT INTO mytable (my_foreign_key) VALUES(LAST_INSERT_ID());

theriddla1019

7:49 pm on Aug 13, 2004 (gmt 0)

10+ Year Member



Thanks Coop, your always a wealth of information :)