SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    Mar 2001
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi. I have installed mysql and php 4.0 on my RH6.0 with apache installed along with the os. When I tested the php installation using the echo command it works. However I find that variables are not being passed from one file to another. The following code in two separate files linked to each other gives me the output 'Welcome '. The value of the variable is not printed at all.


    <A HREF="welcome.php?name=abc"> Hi, I'm abc! </A>

    <?php
    echo( "Welcome $name!" );
    ?>

    Please help.

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I tried out your scripts and they work fine on my computer(php/mysql/apache on win98). I don't know what your problem could be. But, just so you know, echo is not really a php function, so you do not include the parenthesis around what you are trying to display. You can do it if you want, and as you know it works, but that is not what is standard, and it requires more typing.

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Washington State
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this combo :

    <A HREF="welcome.php?name=abc"> Hi, I'm abc! </A>
    Code:
    <?php
    // welcome.php
    
        echo 'Hello '. $HTTP_GET_VARS['name'];
    
    ?>
    If register_globals setting is turned off, calling variables directly will not work. Note your settings via a call to phpinfo(). Also, read about it here :

    http://www.php.net/manual/en/configu...gister-globals

    If this is not the problem then it could be a browser issue, be sure to use proper HTML (<html><body>...). Regarding HTTP_GET_VARS, it's a predefined variable, read about them here :

    http://www.php.net/manual/en/languag...predefined.php

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Sausalito, Ca
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would try this:

    <?php
    echo "Welcome ".$name"."!" ;
    ?>

    php should get the name value pairs out of the query string just by calling the variable name. I could be wrong, but I have never had to do more than ask for it like:

    // the url
    http://www.somedomain.com/?name=value

    // the php
    <?php
    echo $name;
    ?>

  5. #5
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Washington State
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Eli,
    Calling variables directly from url (QUERY_STRING) will not always work although with most setups it does. Note the register_globals setting and information (see links) provided above. If off, using the appropriate predefined variables (like HTTP_GET_VARS) is required.

  6. #6
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Sausalito, Ca
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good to know. Thanks, that will come in handy if/when I run into that problem with a set up.

    We can both agree that the following will not work because of how it is formatted:

    echo "Welcome $name!";
    // where the variable is actually just $name, not $name!


    // the following should work
    echo "welcome ".$name."!";

    // or
    echo "welcome ".$HTTP_GET_VARS['name']."!";

  7. #7
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Washington State
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, it's good to know such things JIC :-) Also, this DOES work just fine :

    echo "Welcome $name!";

    And regarding concatenating the string, use single quotes instead as data within single quotes aren't interpreted (interpolated) by PHP which means it's faster, however subtle.

  8. #8
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Sausalito, Ca
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I stand corrected on all accounts. I learned my php directly from php.net, and have not seen if statements enclosed in colons anywhere. However, I gave it a try and low and behold, it worked.

    What I don't get though is the following:

    $name='Phil';

    echo 'Hello $name!';

    returns Hello Phil!

    Shouldn't the ! at the end of $name make php think it's looking for $name!?

    I tried this out as well, and your right again, it works, but shouldn't it break? Or is the ! not allowed in a variable name, and therefore interpreted as a standalone character?

  9. #9
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Washington State
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Eli,
    Watch your quote use (single vs. double) but yes you're getting it. Also consider this :
    Code:
    <?php
    
      $I = 'I';
      $T = 'T';
    
      echo "h$I, {$T}here."; // hI, There.
    
    ?>

  10. #10
    SitePoint Member
    Join Date
    Mar 2001
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks very much for your replies. The code I had typed was perfectly allright; the problem was with the register_globals line (it was set to off) in the config file.


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
  •