Jump to content

Trying to do this little thing without sessions


play_

Recommended Posts

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?
Link to comment
Share on other sites

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...
Link to comment
Share on other sites

[!--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.
Link to comment
Share on other sites

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 of

get the values
save in hidden field
pass it on when form is submitted

then 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?
Link to comment
Share on other sites

[!--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 of

get the values
save in hidden field
pass it on when form is submitted

then 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.
Link to comment
Share on other sites

[!--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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.