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 …
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
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.