Need help with a simple script

Discussion in 'PHP' started by siber, Oct 23, 2007.

  1. #1
    Hi.
    First of all I should tell that I am very new to PHP. I was going through a book that had an example to capture user data. The fist file “sample2.php” when opened in a browser is supposed to capture two values and pass it to the second file “listing9.3.php” that will print the values initially entered by the user:

    The file “sample2.php” looks like this :
    <html>
    <head>
    <title>Listing 9.2 A simple HTML form</title>
    </head>
    <body>
    <form action="listing9.3.php">
    <input type="text" name="user">
    <br>
    <textarea name="address" rows="5" cols="40">
    </textarea>
    <br>
    <input type="submit" value="hit it!">
    </form>
    </body>
    </html>

    The second file “listing9.3.php” looks like this:

    <html>
    <head>
    <title>Listing 9.3 Reading input from the form in Listing 9.2</title>
    </head>
    <body>
    <?php
    print "Welcome <b>$user</b><P>\n\n";
    print "Your address is:<P>\n\n<b>$address</b>";
    print $user;
    ?>
    </body>
    </html>

    The problem is that after I enter the values in “sample2.php” through the browser, it opens the “listing9.3.php”…. but in the output the values I entered does not get displayed. Could someone please tell me what I am doing wrong?

    Thanks in advance …
     
    siber, Oct 23, 2007 IP
  2. Brewster

    Brewster Active Member

    Messages:
    489
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Hi

    Try this code:

    <html>
    <head>
    <title>Listing 9.2 A simple HTML form</title>
    </head>
    <body>
    <form method="POST" action="listing9.3.php">
    <input type="text" name="user">
    <br>
    <textarea name="address" rows="5" cols="40">
    </textarea>
    <br>
    <input type="submit" value="hit it!">
    </form>
    </body>
    </html>
    PHP:
    and

    
    <html>
    <head>
    <title>Listing 9.3 Reading input from the form in Listing 9.2</title>
    </head>
    <body>
    <?php
    
    $user = $_POST['user'];
    $address = $_POST['address'];
    
    print "Welcome <b>$user</b><P>\n\n";
    print "Your address is:<P>\n\n<b>$address</b>";
    print $user;
    ?>
    </body>
    </html>
    PHP:
    What book did you get the code from ?

    Brew
     
    Brewster, Oct 23, 2007 IP
  3. siber

    siber Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It worked... I thank you a lot.
    I was working on a small project, and for that I was trying few simple codes. This example will help me a lot to continue my work.
     
    siber, Oct 23, 2007 IP
  4. siber

    siber Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I got the example from "SAMS Teach Yourself PHP4 in 24 Hours"
    The files names are different though.
     
    siber, Oct 23, 2007 IP