Jump to content


Photo

Trying to do this little thing without sessions


  • Please log in to reply
7 replies to this topic

#1 play_

play_
  • Staff Alumni
  • Advanced Member
  • 717 posts

Posted 30 March 2006 - 11:41 PM

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?
regex.kat.sh --- regex library
u.kat.sh ---- url shortener
tabbit.org ---- tabbed pastebin

#2 play_

play_
  • Staff Alumni
  • Advanced Member
  • 717 posts

Posted 30 March 2006 - 11:52 PM

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)
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();
    }

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...
regex.kat.sh --- regex library
u.kat.sh ---- url shortener
tabbit.org ---- tabbed pastebin

#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 01 April 2006 - 10:33 AM

You could add a hidden input field to your form

<INPUT type='hidden' name='sql_id' value='$sql_id'>
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#4 play_

play_
  • Staff Alumni
  • Advanced Member
  • 717 posts

Posted 01 April 2006 - 10:05 PM

[!--quoteo(post=360584:date=Apr 1 2006, 05:33 AM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Apr 1 2006, 05:33 AM) View Post[/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.
regex.kat.sh --- regex library
u.kat.sh ---- url shortener
tabbit.org ---- tabbed pastebin

#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 01 April 2006 - 10:23 PM

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?
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#6 play_

play_
  • Staff Alumni
  • Advanced Member
  • 717 posts

Posted 01 April 2006 - 10:37 PM

[!--quoteo(post=360724:date=Apr 1 2006, 05:23 PM:name=Barand)--][div class=\'quotetop\']QUOTE(Barand @ Apr 1 2006, 05:23 PM) View Post[/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.
regex.kat.sh --- regex library
u.kat.sh ---- url shortener
tabbit.org ---- tabbed pastebin

#7 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 02 April 2006 - 12:12 AM

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.
follow me on twitter @PHPsycho

#8 play_

play_
  • Staff Alumni
  • Advanced Member
  • 717 posts

Posted 02 April 2006 - 01:11 AM

[!--quoteo(post=360757:date=Apr 1 2006, 07:12 PM:name=ToonMariner)--][div class=\'quotetop\']QUOTE(ToonMariner @ Apr 1 2006, 07:12 PM) View Post[/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
regex.kat.sh --- regex library
u.kat.sh ---- url shortener
tabbit.org ---- tabbed pastebin




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users