play_ Posted March 30, 2006 Share Posted March 30, 2006 Pretty much, i wanna pass a variable to the same page.I have a form that does a query, and gets the id (mysql_insert_id), the form leads back to current page($_SERVER['PHP_SELF'])Anyways, when the page loads, i'd like to echo out the mysql_insert_id.and here's the thing, i will submit the form a couple more times, and it wont do the query again, but i'd like to print out the mysql_insert_id from when i first clicked submit.Can i do this without sessions? Quote Link to comment Share on other sites More sharing options...
play_ Posted March 30, 2006 Author Share Posted March 30, 2006 Sorry, forgot to add.When the mysql_insert_id is only retrieved once; when the submit button is first clicked. When the page reloads, i skip the query that gets mysql_insert_id.here's a bit of the code:(this bit of code only runs once, when i click submit for the first time, then $_SESSION[i] becomes > 1, and does not perform this query)[code]if ($_SESSION['i'] == 1) { $query1 = "INSERT INTO shirts (title, type, category, date_added) VALUES ('$title', '$type', '$category', NOW())"; $result1 = mysql_query($query1); $sql_id = mysql_insert_id(); }[/code]There are other queries performed, and i need to insert mysql_insert_id into the other query that comes next. So i want to get mysql_insert_id once, and use it again, and again... Quote Link to comment Share on other sites More sharing options...
Barand Posted April 1, 2006 Share Posted April 1, 2006 You could add a hidden input field to your form<INPUT type='hidden' name='sql_id' value='$sql_id'> Quote Link to comment Share on other sites More sharing options...
play_ Posted April 1, 2006 Author Share Posted April 1, 2006 [!--quoteo(post=360584:date=Apr 1 2006, 05:33 AM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Apr 1 2006, 05:33 AM) [snapback]360584[/snapback][/div][div class=\'quotemain\'][!--quotec--]You could add a hidden input field to your form<INPUT type='hidden' name='sql_id' value='$sql_id'>[/quote]And that will be preserved each time the page is refreshed/redirects to itself?Thanks. Quote Link to comment Share on other sites More sharing options...
Barand Posted April 1, 2006 Share Posted April 1, 2006 On each page with a form that you want to pass it to you will need to get the $sql_id from the $_GET or $_POST arrays and put the hidden field in the form.So it's a case ofget the valuessave in hidden fieldpass it on when form is submittedthen same with next page and so on.But as you are using SESSION anyway, why don't you want to use that method for sql_id? Quote Link to comment Share on other sites More sharing options...
play_ Posted April 1, 2006 Author Share Posted April 1, 2006 [!--quoteo(post=360724:date=Apr 1 2006, 05:23 PM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Apr 1 2006, 05:23 PM) [snapback]360724[/snapback][/div][div class=\'quotemain\'][!--quotec--]On each page with a form that you want to pass it to you will need to get the $sql_id from the $_GET or $_POST arrays and put the hidden field in the form.So it's a case ofget the valuessave in hidden fieldpass it on when form is submittedthen same with next page and so on.But as you are using SESSION anyway, why don't you want to use that method for sql_id?[/quote]For some reason i prefer $_POST or GET over a session.i think the less sessions active the better. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted April 2, 2006 Share Posted April 2, 2006 you sholdn't have any problems.....There is one session per client visiting the site (or have left without closing their browser and session has not been destroyed!) but I think you are trying to avoid problems that just won't occur. Quote Link to comment Share on other sites More sharing options...
play_ Posted April 2, 2006 Author Share Posted April 2, 2006 [!--quoteo(post=360757:date=Apr 1 2006, 07:12 PM:name=ToonMariner)--][div class=\'quotetop\']QUOTE(ToonMariner @ Apr 1 2006, 07:12 PM) [snapback]360757[/snapback][/div][div class=\'quotemain\'][!--quotec--]you sholdn't have any problems.....There is one session per client visiting the site (or have left without closing their browser and session has not been destroyed!) but I think you are trying to avoid problems that just won't occur.[/quote]Thanks.But still...i'd prefer if i could use an alternative. not sure why Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.