How do I set a $_SESSION variable

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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'].

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']);

Re: How do I set a $_SESSION variable

Quoted text here. Click to load it

An foreach loop would be less archaic.

To the point: you have to call session_start() on _every_ page.
-- =

Rik Wasmus

Site Timeline