Beginners Guide to PHP - Part 2: POSTing information

PHP Programming Add comments

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!

Click here to see Part 1 of the PHP Tutorial series…

Share and Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • digg
  • Reddit
  • del.icio.us
  • YahooMyWeb
  • Fark

3 Responses to “Beginners Guide to PHP - Part 2: POSTing information”

  1. EggAndBean Archive : Beginners Guide to PHP - Part 1: Hello World Says:

    [...] Click here to view the next installment (part 2), we will look at a slightly more sophisticated example of PHP power. [...]

  2. Beginners Guide to PHP - Part 1: Hello World : EggAndBean Says:

    [...] 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. [...]

  3. Beginners Guide to PHP - Part 3: Database connections : EggAndBean Says:

    [...] 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 [...]

Leave a Reply

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in

Bad Behavior has blocked 111 access attempts in the last 7 days.