Hi I am a newbie and currently using SAMS's PHP, mySQL and Apache all in one 3rd edition. I am using Apache 2.058, PHP 5.1.4. The sams book says this is suppose to work

<?php
$life=42;
function meaningOfLife() {
    global $life;
     echo "The meaning of life is ".$life;
}
meaningOfLife();
?>

but all I am getting displayed in the browser is "The meaning of life is "

    Works OK for me. (I copied and pasted your code exactly as posted above.)

      it also said when I trying this

      <?php
      $life = 42;
      function meaningOfLife() {
           echo "The meaning of life is ".$life;
      }
      meaningOfLife();
      ?>
      
      

      I should get an error, but I am still only getting the single line "The meaning of life is " displayed.

        Hexxx wrote:

        it also said when I trying this

        <?php
        $life = 42;
        function meaningOfLife() {
             echo "The meaning of life is ".$life;
        }
        meaningOfLife();
        ?>
        
        

        I should get an error, but I am still only getting the single line "The meaning of life is " displayed.

        Depending on your php.ini file, you might not see the "error" (really a "warning" or "notice" in this case). You might try adding the following lines to the top of you script to make sure all errors are being reported:

        <?php
        ini_set('display_errors', 1); // display errors to the browser
        error_reporting('E_ALL'); // show all type of errors/warnings/notices
        // rest of script...
        ?>
        

          also in the new php / mysql (cant remember) havent they stopped using globals?

          you could look into setcookie() (http://www.php.net/setcookie) ... i just started using them and they are a great help.

          the use of global is just if you want your browser to remember the value of $life over multiple pages... something cookies do quite well 🙂

            also if you want a really good localhost server proggy thingy 😉, i use WAMP .. it's a french program but it's all in english etc.. i think it's fantastic..

            lastest PHP / MySQL.. and i've not have a problem with it since the day i installed.

              Write a Reply...