SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru
    Join Date
    Nov 2002
    Location
    Dubai
    Posts
    714
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    User interaction in PHP

    I am in the process of learning PHP from Kevin Yank's book. I was trying out a code and need help. I created an HTML file, the body of which is as follows:
    <body>
    <a href="welcome.php?name=Kevin"> Hi, I'm Kevin! </a>
    </body>

    I also created a php file, welcome.php in the body of which I typed as follows:
    <?php
    echo( "Wlcome to our Web site, $name!" );
    ?>

    But, when I go to the link, Hi, I'm Kevin and click on it, I only get the following on my webpage:
    Welcome to our Web site, !
    The name is not being accepted by the variable. What is the problem? Can anyone help me?
    I am running on Apache.

  2. #2
    Shiver me timbers!! anthony_irl's Avatar
    Join Date
    Aug 1999
    Location
    Dublin, Ireland
    Posts
    495
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:

    PHP Code:
    <?php
    echo( "Welcome to our Web site, " $_GET['name']);
    ?>
    Anthony - How's tings?

    24 hours in a day, 24 beers in a case. Coincidence? I think not.
    Contact me by: PM Email NEW! Carrier Pigeon

  3. #3
    Mal Reynolds Mandibal's Avatar
    Join Date
    Aug 2003
    Location
    Columbus
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes...do as Anthony posted. The problem is that register_globals in php.ini is now set to off by default(good thing) where as I believe in Kevins book the assumption is that its on. When off you need to use the $_GET global array.
    Erh

  4. #4
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    And to understand why, I recommend reading this. Especially the warning in the box.

  5. #5
    SitePoint Guru
    Join Date
    Nov 2002
    Location
    Dubai
    Posts
    714
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks to all of you. The code does work now. But I am still having a problem with my "if else" control structure.

    How do I modify the following code:

    If ( "Kevin" == $firstname and "Yank" == $lastname ) {
    echo( "Welcome, oh glorious leader!" );
    } else {
    echo( "Welcome to my Website, $firstname, $lastname!" );

  6. #6
    SitePoint Guru
    Join Date
    Nov 2002
    Location
    Dubai
    Posts
    714
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    User interaction in PHP - Control Structures

    Sorry, I should have used the same method for this as well. I am getting it now. Anyway, thanks once again.


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
  •