Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2009
    Location
    Chicago, IL
    Posts
    54
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Declare variables like ASP?

    I am used to coding in basic ASP code, and I set variables like so:

    Code:
    <% dim variable1 %>
    <% variable1 = "name goes here" %>
    And then, on any page, I can use code like this:

    Code:
    <% =variable1 %>
    And it will out put "name goes here." I want to do this same thing in PHP, but I'm having trouble.

    Here is the code that I wrote:

    Code:
    <?php
    
    $event1_month = "May";
    $event1_day = "05";
    $event1_title = "Candidate Filling Period Ends";
    
    ?>
    And on a page, I have this code:

    Code:
    <?php echo $event1_day; ?>
    But it is not outputting anything. Can someone show me how to correct this and get it working how I want?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    This is correct.
    Are you declaring in the same script you are printing off of? If not, you need to either include or require the script declaring the variables before you can print them.


  •  

    Tags for this Thread

    Posting Permissions

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