Jump to content

How to catch Session Variable undifened exeption


Leftfield

Recommended Posts

How can i catch this exception and run the catch code  , and stop the error message displaying on the webpage . Thanks

<?php
  try{
   
    
    echo $_SESSION['btn'];
    
}
catch(Exception $ex)
{
    
    $_SESSION['btn'] = "Check Available";
    echo $_SESSION['btn'];
}
?>"/>

 

Please help

Nope there is still a problem

 

I set my session like this

 

<?php
{
if(isset($_SESSION['txt'])){//When is step through the code it goes to else telling me it is not set .
     
     $_SESSION['txt'] = "Next >";
     echo $_SESSION['txt'];     
}
else
     {
     
     $_SESSION['txt'] = "Check Available";
     echo $_SESSION['txt'];
}

}



?> "/>

 

But when i debug my code it tells me my session is not set

 

And if i use session_start();

 

i get the following error

 

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\Program Files\xampp\htdocs\OnlineBookingsPhp\index.php:199) in C:\Program Files\xampp\htdocs\OnlineBookingsPhp\index.php on line 210 Call Stack #TimeMemoryFunctionLocation 10.2265381640{main}( )..\index.php:0 24.1850394048session_start ( )..\index.php:210

 

 

Any ideas ???

Ok it works without an error  .

 

But i am trying to set a button value to my session like so

  <input id="Submit" type="submit" name="submit" value="<?php echo $_SESSION['txt']; ?>"/></div>

But the debugger still skips this line

 

if(isset($_SESSION['txt'])){//When is step through the code it goes to else telling me it is not set .

 

Maybe isset is lost after postback

 

is there maybe a better way to do this or should i use it as a session is the only thing that remain after postback

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.