SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Oct 2012
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Just started my first PHP book

    Hi All,

    I have Larry Ullmans PHP book and am just experimenting with something to see how it works.

    Here is what I am trying to do within the same page

    <?php $result = "This is a test" ?>

    <!--Some html-->

    <?php echo "$result" ?>

    When I run this I get an undefined variable error.....grrrr

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,136
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Well, not 100% that this would produce an undefined variable, but you are missing the semi-colon after each PHP statement.

    PHP Code:
    <?php $result "This is a test"?>
    PHP Code:
    <?php echo "$result"?>

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2012
    Location
    United Kingdom
    Posts
    78
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    There is nothing in the code above that would produce an undefined error. So unless some other code is triggering this error, or one of your variable names is different (remember they're case sensitive), then the above has no reason to output an error.

    @cpradio, omitting the last semicolon before the closing PHP tag is optional, so it would not be the cause of this (or any) error.

  4. #4
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,136
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by modernW View Post
    @cpradio, omitting the last semicolon before the closing PHP tag is optional, so it would not be the cause of this (or any) error.
    Partially why I prefixed it, as if that were the problem, it should have produced a syntax error.

  5. #5
    SitePoint Addict kduv's Avatar
    Join Date
    May 2012
    Location
    Maui, HI
    Posts
    211
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    The error should tell you exactly which variable is undefined. What is the entire error message?
    Keith
    Freelance web developer
    http://www.duvalltech.com/


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •