In the first part of this tutorial, we looked at how PHP can be used to display dynamic data, like todays date. You’ve also by now hopefully figured out the process of making a .php file, uploading it to your web host, and running it. With that much done, its time to try something a little more adventurous!
For this, you need to create two .php files – the first one should contain the following and be called “part2a.php”:
<html>
<body>
<form action="part2b.php" method="post">
<input type="text" name="myname" />
<input type="submit" value="Submit" />
</form>
</body>
</html>
And the second file should contain the following, and be called “part2b.php”:
<?php
echo "You entered this on the previous page: ".$_POST['myname'];
?>
And your done! Upload both files to the same directory on your webhost, and then go to yourwebhost.com/part2a.php.
So what is happening here? Well, the first page is taking in some data from the user into a form. When the user then clicks submit, this data is the POSTed to a nominated new page, into which code is placed to deal with this incoming data. This is simple example of passing data, but if you can understand this, you’ve pretty much understood all you need to know to make more advanced things happen!
March 25th, 2007 at 3:47 pm
[...] Click here to view the next installment (part 2), we will look at a slightly more sophisticated example of PHP power. [...]
July 20th, 2007 at 4:40 pm
[...] Click here to view the next installment (part 2), we will look at a slightly more sophisticated example of PHP’s power. Share and Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages. [...]
October 31st, 2007 at 9:51 pm
[...] uploading it to a server and accessing its results through a web browser. If you stuck around for Part 2 in this series, you might even have dabbled with a Form or two. POSTing to a Form is one way of [...]