SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    May 2003
    Location
    englan d
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Utter newbie having problems

    Im using the php book from this site, and im on the bit where we start doing php.... and this parts not working, the welcome.php?name=kevin stuff....
    i dunno what im doing wrong, the php is working fine for the var stuff, so i figure it should be working for this? :\

    source codes for the html and php files:


    ---welcome.htm---
    <html>
    <head>
    <title>todays date</title>
    </head>
    <body>
    <p>
    <A HREF="welcome.php?name=Kevin"> Hi, I'm Kevin! and i dont work! </A>
    </p>
    </body>
    </html>

    ---welcome.php---
    <html>
    <head>
    <title>todays date</title>
    </head>
    <body>
    <?php
    echo(' Welcome $name! ');
    echo(" Welcome $name! ");
    echo(" Welcome ". $name . "! ");
    ?>
    </body>
    </html>

    I tryed every way to get it to work, even the way thats not suposed to. ^_^
    Im running apache with php and mysql, i think its all setup and running right.....
    ... help?

    http://80.6.170.86/php/

    is where all my files are....

  2. #2
    SitePoint Zealot LiamW's Avatar
    Join Date
    Mar 2003
    Location
    Hamilton, Ontario
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You probably have php with register globals off.

    To access variables from a url you use $_GET['name']

    So put $name = $_GET['name']; as the first line of php code in the welcome.php file above the echo statements.

  3. #3
    SitePoint Member
    Join Date
    May 2003
    Location
    englan d
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you, it works now.

  4. #4
    SitePoint Zealot LiamW's Avatar
    Join Date
    Mar 2003
    Location
    Hamilton, Ontario
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To read more about the new arrays click here

    Basically when you are passing variables from urls, forms, sessions(you'll learn more about these later) etc you can't just access them in your page by calling the name of the variable. This is for security reasons.

    If you have variables posted from a form using the post method, you'd access them by using

    $name = $_POST['name'];
    Where 'name' is the variable name from the form

    Hopefully I explained it ok. If you're still confused just let us know.

  5. #5
    SitePoint Member
    Join Date
    May 2003
    Location
    englan d
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmmm, any idea how you turn register globals or whatever on? :\

  6. #6
    SitePoint Member
    Join Date
    May 2003
    Location
    englan d
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah cool, well if its for security reasons....

  7. #7
    SitePoint Zealot LiamW's Avatar
    Join Date
    Mar 2003
    Location
    Hamilton, Ontario
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Believe me it's much better to use the methods above. It may seem like more work now but like I mentioned it's for security reasons and in the long run you'll be glad you used them.
    It looks like you are using the first copy of the book from Sitepoint. They have since released a newer revised edition which takes into consideration the fact that newer verisons of php now come with register globals off.
    I don't know if it still applys but at one time owners of the old version could get a copy of the new book at no charge or something along those lines.
    Might want to look into that or just remember how to access the variables when reading the rest of the book.


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
  •