PHP and Forms
Last update on: 10-09-2008You've already seen the declaration of a variable, manipulations and others, here you will learn how to retrieve and verify data forms.
Retrieving values of text fields
<form method="post" action="verify.php"> First Name: <input type="text" name="name1"><br /> Last Name: <input type="text" name="name2"><br /> <input type="submit" name="button" value="Send.."> </form>
//we verify with the empty() function if the field name1 and name2 are empty if(empty($_POST['name1']) OR empty($_POST['name2'])) { //if one of them is empty we print an error message print 'the field First name and/or Last name is/are empty'; } //else we print a confirmation message else{ print 'Thank you '.$_POST['name1']; }
Verify an email address:
//we verify with the regex() function, there are others ways to do this... //but that will be for the comming lessons. if(!ereg("\.",$_POST['email']) || !ereg("@",$_POST['email'])) { //the . or @ or both doesn't exist on the email field print 'The email address is not valid'; } else{ print 'email address is ok'; }
PHP and MySQL's lessons:
Introduction To PHPGet Started With PHP
PHP Variables
PHP Variables Of Environment
PHP Conditions
PHP Looping
PHP Cookies
PHP Working With Dates
PHP Working With Arrays
PHP Working With Files
PHP Play With Strings
PHP And Forms
Send Emails With PHP
The Include Statement
Get Started With MySQL
MySQL Update And Delete
The WHERE Clause
MySQL Functions
Guestbook Script
Websites Directory Script
Multiple Pages With PHP
Create Your Forum With Php

