1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Development Started PHP4

Discussion in 'Software' started by Miku, 12 Jul 2003.

  1. Miku

    Miku What's a Dremel?

    Joined:
    11 Mar 2003
    Posts:
    328
    Likes Received:
    0
    Well i just started learning PHP4, but the first files didn't work, although they didn't seem to have anything wrong...

    So here is the source code of text.html:

    <HTML>
    <HEAD></HEAD>
    <BODY>
    <FORM METHOD=GET ACTION="text.php">
    Who is your favourite author?
    <INPUT NAME="Author" TYPE="TEXT">
    <BR>
    <BR>
    <INPUT TYPE=SUBMIT>
    </FORM>
    </BODY>
    </HTML>

    Ande here is text.php:

    <HTML>
    <HEAD></HEAD>
    <BODY>
    Your favorite author is:
    <?php
    echo $Author;
    ?>
    </BODY>
    </HTML>

    What's wrong here?
     
  2. RTT

    RTT #parp

    Joined:
    12 Mar 2001
    Posts:
    14,120
    Likes Received:
    74
    For a while now, php's 'register globals' setting has by default been set to OFF for security and various other reasons (to try to make people code better, and to make them think about how they want variables to be assigned).
    This means that variables sent by URLs or forms have to be accessed in a different way.

    You would now have to use $_GET[Author] instead of $Author in text.php.

    Likewise if you were using the POST method (which is preferable to GET), you would have to use $_POST[Author].

    Coding using $_POST, $_GET, $_REQUEST etc and with register_globals off is much better than just using $var :)

    Hope this helps :)
     
  3. SerpentBlade

    SerpentBlade What's a Dremel?

    Joined:
    10 Apr 2003
    Posts:
    94
    Likes Received:
    0
    Also, if you don't like using the $_GET/POST/SESSION variables... you can use: extract($_GET) and it will put all the [variables] into $variables as you like to use it.

    So if you want to use a lot of variables from a form in the future, use: extract($_POST);
    thus giving you the $author, and other $variables you like using

    Just another one of those PHP hints.. register globals sux
     
  4. RTT

    RTT #parp

    Joined:
    12 Mar 2001
    Posts:
    14,120
    Likes Received:
    74
    I disagree. It forces you to think about how your variables are going to be designed, and makes it a lot easier to debug your scripts 6 months down the line. I used to hate register_globals set to off, now I wouldnt think NOT to use GET/POST/REQUEST -- its the best way :)
     
  5. Sid

    Sid Banned

    Joined:
    13 Mar 2002
    Posts:
    1,413
    Likes Received:
    0
    Agreed. Much more precise and more secure.
     
  6. bradford010

    bradford010 Bradon Frohman

    Joined:
    7 Dec 2001
    Posts:
    3,426
    Likes Received:
    0
    Just a note about good programming practice.

    Use

    $_GET['foo']

    as opposed to

    $_GET[foo]

    (note the inverted commas).
     
  7. RTT

    RTT #parp

    Joined:
    12 Mar 2001
    Posts:
    14,120
    Likes Received:
    74
    ''s cause prioblems in mySQL queries and other strings, so why bother?
     
  8. Sid

    Sid Banned

    Joined:
    13 Mar 2002
    Posts:
    1,413
    Likes Received:
    0
    I often have problems with parse errors when using them in mysql commands. I was wondering how to get round that actually. To be honest, that is the proper way to do it (with 's), so that's the way it should be done. There has to be official standards that programmers adhere to rather than taking shortcuts.
     
  9. bradford010

    bradford010 Bradon Frohman

    Joined:
    7 Dec 2001
    Posts:
    3,426
    Likes Received:
    0
    I said in my post, it's good programming practice. If we're going down that road, why bother keeping register_globals on when turning it off can be a bit easier and save you a good few seconds?

    (btw, there's no extra ' in 's. Just pointing that out since it can make things a bit confusing ;)).


    PHP:
    $query "SELECT * FROM content WHERE title='$foo['bar']' LIMIT 1"
    If that's giving you problems, it is so simple to just do

    PHP:
    $query "SELECT * FROM content WHERE title='".$foo['bar']."' LIMIT 1"
    voila, problem solved.

    :)
     
  10. Sid

    Sid Banned

    Joined:
    13 Mar 2002
    Posts:
    1,413
    Likes Received:
    0
    Ah, excellent. Thank you.
     
  11. RTT

    RTT #parp

    Joined:
    12 Mar 2001
    Posts:
    14,120
    Likes Received:
    74
    There is sod all difference between &_GET[blah] and $_GET['blah'] - the difference between register_globals on and off is huge... :rolleyes:
     
  12. bradford010

    bradford010 Bradon Frohman

    Joined:
    7 Dec 2001
    Posts:
    3,426
    Likes Received:
    0
    ffs RTT, there really is no need to start being childish about it. I can only assume you'd still be PMing me asking for help, had I not pissed you off about something....
     
  13. RTT

    RTT #parp

    Joined:
    12 Mar 2001
    Posts:
    14,120
    Likes Received:
    74
    I'm sorry? :confused:

    I am only questioning your logic... my apologies if I came across as being arrogant. My point was that it still works identically and won't post any problems for anyone unfamiliar with the method below which you correctly pointed out.

    ->

    Code:
    $query = "SELECT * FROM content WHERE title='".$foo['bar']."' LIMIT 1"
    
     

Share This Page