0

I get an undefiend variable error when i call another $_SESSION but when i remove this piece of code it shows no errors, I am using $_SESSION in order to pass one variable to another php script, can anyone enlighten me on what may be causing this issue?

I know the variable is defiened but for some reason calling a $_SESSION causes this error?

<div>
    <? 
    if(empty($item_details['trucks'])) {
        include_once ('trucks.php');
        $_SESSION['runmapapi'] = 'start'; 
        //$runmapapi == true;
        echo '<p> Success</p></div>'; 
    } else {
        echo '<p>failed</p></div>';
    } 
    ?>
<div>
    <p>Cars</p>
</div>  
</div>
</div></body>
<? } ?>
<? } ?>   
<?= $print_footer; ?>
1
  • Undefined variable i edited my post to include the code, should i post the include php file as well? Commented May 31, 2012 at 6:12

1 Answer 1

1

when you are using session variable, you have to initialize the session by using

session_start();

so wherever you use any of the session variable in your page, make sure you first declare the session_start()

so in your page it should be

//initialize session to use session variable
session_start();
include_once ('trucks.php');
$_SESSION['runmapapi'] = 'start'; 
Sign up to request clarification or add additional context in comments.

3 Comments

hi Ibrahim i have the session_start bit in my included trucks.php file
the error states that you have not initialized the session. can you post the code from trucks.php
hello Ibrahim thanks for your quick response, i have just commented out that line so that error no longer exists, i will vote for your response for your great help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.