ExpertRating - Online Certification and Employment Testing ExpertRating - Online Certification and Employment Testing ExpertRating - Online Certification and Employment Testing

ExpertRating Home
ExpertRating Benefits
Recommend ExpertRating
Suggest More Tests
Privacy Policy
FAQ
Login
 
PHP Tutorial - Index
PHP Tutorial - Introduction to PHP
PHP Tutorial - Your First PHP Script
PHP Tutorial - Operators
PHP Tutorial - Conditional and Looping
PHP Tutorial - Functions
PHP Tutorial - Classes and Objects
PHP Tutorial - Working with Forms
PHP Tutorial - Advanced PHP Topics
PHP Tutorial - Advanced Class Concepts
     

 
Online Personal Trainer Certification
Personal Trainer Certification (Spanish)
Six Sigma Certification
Find a Personal Trainer
Project Management Certification
Six Sigma Certification
Six Sigma Black Belt Certification
Master Black Belt Certification
Six Sigma Green Belt Certification
Life Coach Certification
Lean Management Certification
Lean Six Sigma Certification
First Aid Certification
CPR Certification
Yoga Certification
Aerobics Certification
Pilates Certification
Business Analyst Certification
SEO Certification
Online Business Writing Course & Certification
Baby Sitting Course & Certification
Time Management Certification
Health Club Management Certification
Medical Coding Certification
Medical Billing Certification
Business Analysis Course
Master Trainer Certification
Total Quality Management Certification
Kaizen Certification
Creative Writing Certification
Event Management Certification
Test Search by Job Title
Administrative Assistant Certification
Virtual Assistant Certification
  All Online Courses
   

   
   
   
   
   
   

   
  Home > Courses, Tutorials & eBooks > PHP Tutorial >Working with Forms
 

PHP Tutorial - Working with Forms

 
Page 1 of 1
 

PHP comprises of a very powerful feature of handling HTML forms. The basic concept in this is that any form element in an HTML page will automatically be available in the PHP scripts.

Creating Forms

The forms in PHP are created in the same way as they were created in HTML. The most important thing in this that any form element in an HTML page will be available to the PHP script.

Example

<html>

<body>

<form action="action.php" method="POST">
Enter your name:
<input type="text" name="name" />
Enter your age: <input type="text" name="age" />
<input type="submit" />
</form>  
</body>
</html>

 

 In the above example the HTML page contains two fields of input type and a submit button. When the user fills in the forma and hits the submit button then the “action.php” file will be called. The purpose of action and method in the form tag will be explained later.

Submitting Data

After designing a form, the first step is to set up the form to submit its data to the PHP script. The submission of data is done through the action attribute of the <form> tag. When a form is submitted, the web server executes the PHP script and passes to it the values which were submitted in the submission. This attribute defines the URL to which the data is submitted.

Example
If the PHP script is called “welcome.php” then the <form> tag would be like:   <form action=”welcome.php” method=”POST”>  
 

Post and Get Operations

There are two methods that can be used while creating a form in HTML. These methods are post and get.  

Example

<form action=”welcome.php” method=”POST”>  

Or  

<form action=”welcome.php” method=”GET”>  

 


The get and the post method do the same thing. If no method is specified then the default method is taken as GET by the web server.   The get method puts the contents of the form right in the URL. This method has certain disadvantages. The first one being that there is a limit that how much data can be sent through the form using the get method. It depends on the web server’s operating system and software and many systems have a limit of 256 characters. The second thing is that individual get queries may be stored in the web server’s logs   The post method was created to correct the inadequacies of the get method. Firstly, the information that is sent through the post method is not visible in the URL. Secondly, the data cannot be deciphered by looking into the web server logs. The limit on the amount of data that can be sent from a form is not as small as that of get.      

Cookies  

A cookie is used to identify a user. A cookie is a small file that is embedded by the server on the user’s computer. In this when the same computer requests for a page with a browser, it will send the cookie too. Each cookie consists of a name, value, expiry date, and host and path information. The size of an individual cookie is limited to 4 KB. With PHP, cookie values can be created and retrieved.

Creating Cookie

The setcookie() function is used to create cookies. The setcookie() function should be called before any other content is sent to the browser. The setcookie() function appears before the HTML tag. The setcookie() function accepts the cookie name, cookie value, expiry date, path, and domain. All the arguments to this function are optional apart from the cookie name parameter.  

Syntax
Setcookie(name, value, expire, path, domain);
 

Example
<?php setcookie("usal", $sal, time()+3600); ?>   <html> <body>   <p> A cookie was set on this page! The cookie will be active when the client has sent the cookie back to the server. </p>   </body> </html>  
 

In the above a example a cookie named usal was set with the setcookie() function. This cookie will expire in one hour as the parameter of time given in the function is set to 1 hour.

Retrieving a Cookie Value

When a cookie is set, then the cookie name is used as a variable by PHP. To access the cookie the cookie name has to be referred as a variable.  

Example

<html>
<body>
<?php
if (isset($_COOKIE["usal"]))
echo "Welcome " . $_COOKIE["usal"] . "!<br / >";
else
echo "You are not logged in!<br /> ";
?>
</body>
</html>

 

         

 

 

 
     
Home  |  About Us  |  Privacy Policy  |  Site Map  |  FAQs  |  Contact Us
 
© ExpertRating 2006. All Rights Reserved.