Monday, 8 August 2016

PHP 5 FORM HANDLING(create a simple server side form in html)

What is PHP?

  • PHP is an acronym for "PHP: Hypertext Preprocessor.
  • PHP scripts are executed on the server.


PHP is an amazing and popular language!
It is also easy enough to be a beginner's first server side language.

What Can PHP Do?

  • PHP can generate dynamic page content
  • PHP can create, open, read, write, delete, and close files on the server
  • PHP can collect form data
  • PHP can send and receive cookies
  • PHP can add, delete, modify data in your database
  • PHP can be used to control user-access
  • PHP can encrypt data
With PHP you are not limited to output HTML. You can output images, PDF files, and even Flash movies. You can also output any text, such as XHTML and XML.

below is a sample code for a simple form using php

your html file:

<doctype html>


<html>  
<body>

<form action="test.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>

</body>
</html>

here is what your test.php should look like

<html>
<body>

Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>

</body>
</html>


your output should look like this
Welcome John(if your inputed name is john)
Your email address is john.doe@example.com(if this is your email address)

the above example is done using http:post this could also be achieved using HTTP:GET
The PHP superglobals $_GET and $_POST are used to collect form-data.
click here to know the difference between get and post

Share:

0 comments:

Post a Comment