PHP and Forms

You’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

1- The HTML form:

<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>

2- The verify.php file:

<?php
//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:

<?php
//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';
}
?>
Filed under PHP and MySQL. You can follow any responses to this entry through the RSS 2.0. You can leave a response by filling following comment form or trackback to this entry from your site

PHP and MySQL' CATEGORY »

Introduction to PHP
Get 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
Simple PHP guestbook script
Simple PHP websites directory script
Multiple pages with PHP
Create your forum with php

No Responses for “Create your forum with php”

  1. robert says:

    thnk u for the good tutorial

Leave a Reply