How do I set a $_SESSION variable

This is a discussion on How do I set a $_SESSION variable within the PHP Language forums, part of the PHP Programming Forums category; This is page is called to delete a row on a table using form input. I set a session variable ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-14-2007
Big Moxy
 
Posts: n/a
Default How do I set a $_SESSION variable

This is page is called to delete a row on a table using form input. I
set a session variable based on the result of mysql_query and want to
pass it back to the caller like this.

if (mysql_query($deleteSQL,$emailmanager) &&
mysql_affected_rows()>0) {
$_SESSION["mysql_query_result"] = "Your email address has been
successfully removed";
}else {
$_SESSION["mysql_query_result"] = "Your email address was not
found. Please try again";
}

.....

Here is the return code (generated by Dreamweaver) -

header(sprintf("Location: %s", "http://".$_SERVER['HTTP_HOST'].
$deleteGoTo));

How do I return the session variable to the caller? The $_SESSION
array does not exist on return to the caller. I check it using this
print code -

while ($var = each($_SESSION)) {
printf ("Session key <b>%s</b> has the value of: <b>%s</b><br>",
$var['key'], $var['value']);
}

Reply With Quote
  #2 (permalink)  
Old 08-14-2007
Rik
 
Posts: n/a
Default Re: How do I set a $_SESSION variable

On Tue, 14 Aug 2007 00:33:48 +0200, Big Moxy <bigmoxy@gmail.com> wrote:

> This is page is called to delete a row on a table using form input. I
> set a session variable based on the result of mysql_query and want to
> pass it back to the caller like this.
>
> if (mysql_query($deleteSQL,$emailmanager) &&
> mysql_affected_rows()>0) {
> $_SESSION["mysql_query_result"] = "Your email address has been
> successfully removed";
> }else {
> $_SESSION["mysql_query_result"] = "Your email address was not
> found. Please try again";
> }
>
> ....
>
> Here is the return code (generated by Dreamweaver) -
>
> header(sprintf("Location: %s", "http://".$_SERVER['HTTP_HOST'].
> $deleteGoTo));
>
> How do I return the session variable to the caller? The $_SESSION
> array does not exist on return to the caller. I check it using this
> print code -
>
> while ($var = each($_SESSION)) {
> printf ("Session key <b>%s</b> has the value of: <b>%s</b><br>",
> $var['key'], $var['value']);
> }


An foreach loop would be less archaic.

To the point: you have to call session_start() on _every_ page.
--
Rik Wasmus
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 08:07 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0