Results 1 to 14 of 14

Thread: Simple example not working

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Simple example not working

    I'm trying out a simple PHP example from this page:

    http://hotwired.lycos.com/webmonkey/...tw=programming

    Here's index.php:

    PHP Code:
    <html
     <
    head
     <
    title>My Form</title
     </
    head
     <
    body

     <
    form action="bad.php" method=post

     
    My name is:
     <
    br> <input type="text" name="YourName"

     <
    pMy favorite dirty word is
     <
    br> <input type="text" name="FavoriteWord"
     <
    p>

     <
    input type="submit" name="submit" value="Enter My Data!">
     </
    form>

     </
    body>
     </
    html
    And here is bad.php:

    PHP Code:
    <html>
    <head>
    <title>Perv!</title>

    </head>

    <body bgcolor="#FFFFFF" text="#000000">

    <p>
    Hi <?php print $YourName?>

    <p>
    You like the word <b> <?php print $FavoriteWord?> !?! </b>

    <p>You oughta be ashamed of yourself!

    </body>
    </html>
    When I run it, I get this error on bad.php:

    Notice: Undefined variable: YourName in C:\My Documents\My Webs\php\bad.php on line 10


    You like the word
    Notice: Undefined variable: FavoriteWord in C:\My Documents\My Webs\php\bad.php on line 13
    !?!


    What am I doing wrong? In ASP, whenever I submitted a form, I had to request the variables passed. I don't see it so far in PHP.

    Any help is good
    Thx.

  2. #2
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    It's probably because you have register globals off, so you need to either make the vars aviable with:

    Code:
    global $YourName;
    or the better way:

    Code:
    $_REQUEST['YourName']; //POST or GET
    $_POST['YourName']; //POST only
    $_GET['YourName']; //GET only
    It's more secure if you use $_POST because then the user can just append a variable to the query string to "hack" your code

  3. #3

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Thanks Rick. I used this:

    PHP Code:
    <?php



    global $YourName;
    global 
    $FavoriteWord;

    $YourName $_REQUEST['YourName'];
    $FavoriteWord $_REQUEST['FavoriteWord'];
    ?>

    But instead of this, how can I make life easier... how can I register globals "on" ?

  4. #4

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    NM... I checked out php.ini and found it.

    I'm learning something about php: Just about EVERYTHING is in that php.ini file. Bugger eh?

  5. #5
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    it had nothing to do with globals.

    you need to find this line and uncomment it in the ini file. it is not bad but just a warning.

    error_reporting = E_ALL & ~E_NOTICE

  6. #6
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    Originally posted by Rick Bull

    or the better way:

    Code:
    $_REQUEST['YourName']; //POST or GET
    $_POST['YourName']; //POST only
    $_GET['YourName']; //GET only
    It's more secure if you use $_POST because then the user can just append a variable to the query string to "hack" your code
    no, REQUEST is not safe. it also controls _FILES[]

    use GET or POST whenever you can

  7. #7

  8. #8

    Thread Starter
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    What is _FILES[]; ?

  9. #9
    New Member
    Join Date
    Jan 2003
    Posts
    11
    I just put
    PHP Code:
    error_reporting(65); 
    in a common file. Only reports the really nasty errors that way. doesn't bother with Notices, or Warnings.

  10. #10
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    Originally posted by mendhak
    What is _FILES[]; ?
    $_FILES[] is the superGlobal for uploading files to the server. REQUEST also controls this.

    ric, that is the same and probably an easier way to do it if you didn't have access to the ini file.

  11. #11
    Fanatic Member Gimlin's Avatar
    Join Date
    Dec 2001
    Location
    Hell
    Posts
    734
    you can also REQUEST cookies.

  12. #12
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    oh yeah :P

  13. #13
    New Member
    Join Date
    Jan 2003
    Posts
    11
    Originally posted by Gimlin
    you can also REQUEST cookies.
    I WANT COOKIES NOOOOOOW MOM!!

  14. #14
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by ricmitch
    I WANT COOKIES NOOOOOOW MOM!!
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

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



Click Here to Expand Forum to Full Width