logo
g Text Version
Beauty & Self
Books & Music
Career
Computers
Education
Family
Food & Wine
Health & Fitness
Hobbies & Crafts
Home & Garden
Money
News & Politics
Relationships
Religion & Spirituality
Sports
Travel & Culture
TV & Movies

dailyclick
Bored? Games!
Nutrition
Postcards
Take a Quiz
Rate My Photo

new
Painting
Heart Disease
Horror Literature
Dating
Hiking & Backpacking
SF/Fantasy Books
Healthy Foods


dailyclick
All times in EST

Full Schedule
g
g PHP Site

BellaOnline's PHP Editor

g

Using HTML Form Variables with PHP

Guest Author - Diane Cipollo

In this tutorial, we will take a look at how to pass the value of a variable from a webpage to a PHP program. Essentially, there are two parts to this. The first part is collecting information from your website visitor and passing that information to the processing program. The second part is coding the processing program to “recognize” each variable and the information it carries. What happens to the information then depends on the purpose of the program. Let’s follow along with a couple example variables as they make their way from the webpage to a processing program called program.php.

The easiest way to collect information from your visitors is to use an HTML form. Each piece of information that you wish to collect is assigned to a program variable and each variable is given a unique name. For our example, we will be asking the visitor is give us their first name and email address.

  1. First, we need to give a unique name of each variable. Let’s make it easy to tell them apart by giving each variable a name that suggests what information it will hold. We will call the first name variable “first_name” and the email variable “email_address”. Next, we will use the HTML input tag to create the input fields in the web browser. Notice that the value of each variable is initially set to null (value="") inside the tags.

    <input type="text" name="first_name" value="" size="30" maxlength="10">


    <input type="text" name="email_address" value="" size="30" maxlength="10">


  2. We need to send the collected information to the processing program called program.php. We can do this with the action attribute in the HTML form tag.

    <form method="post" action="program.php">


  3. Of course, we will need a Send button to send the form on its way to the program.

    <input type="submit" value="Send">


  4. Now, the program needs to recognized the information. You can think of it as checking to see if the information made its way to the program. The first section of code below says “if the first_name variable passed from the web form,called $_POST['first_name'], is NOT (!) empty, then set the value of $first_name to the value of $_POST['first_name']. The second section of code does the same for the email_address variable.

    if(!empty($_POST['first_name']))
    {
    $first_name = $_POST['first_name'];
    }

    if(!empty($_POST['email_address']))
    {
    $email_address = $_POST['email_address'];
    }


    Now, the two variables $first_name and $email_address are ready to be used in the rest of the program.

    Note–When asking for personal information such as an email address, you should build security features into your program that will protect your visitor’s information.




This site needs an editor - click to learn more!

Add Using+HTML+Form+Variables+with+PHP to Twitter Add Using+HTML+Form+Variables+with+PHP to Facebook Add Using+HTML+Form+Variables+with+PHP to MySpace Add Using+HTML+Form+Variables+with+PHP to Del.icio.us Digg Using+HTML+Form+Variables+with+PHP Add Using+HTML+Form+Variables+with+PHP to Yahoo My Web Add Using+HTML+Form+Variables+with+PHP to Google Bookmarks Add Using+HTML+Form+Variables+with+PHP to Stumbleupon Add Using+HTML+Form+Variables+with+PHP to Reddit




RSS | Related Articles | Editor's Picks Articles | Top Ten Articles | Previous Features | Site Map


For FREE email updates, subscribe to the PHP Newsletter


Past Issues


print
Printer Friendly
bookmark
Bookmark
tell friend
Tell a Friend
forum
Forum
email
Email Editor


Content copyright © 2013 by Diane Cipollo. All rights reserved.
This content was written by Diane Cipollo. If you wish to use this content in any manner, you need written permission. Contact BellaOnline Administration for details.

g


g features
Archives | Site Map

forum
Forum
email
Contact

Past Issues
memberscenter


vote
Poetry
Daily
Weekly
Monthly
Less than Monthly



BellaOnline on Facebook
g


| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2013 Minerva WebWorks LLC. All rights reserved.


BellaOnline Editor