Final Project Page 2




Projects

2 | 3 | 4 | 7 | 10 | 12 | 13 | 17 | 18 | 19 | 20 | Final



Registration Form Tutorial
Part 1: Registration Script


Copy the following script into a blank document in a text editor, Netscape Composer, Dreamweaver, etc. and save as register.php.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

61
62
63
64
65
66
67
68
69
70
71
72
73
74
75

76
77
78
79
80
81
82
83
84
85
86
87
88
<?php // Script 8.10 - register.php (second version after Script 8.9)
// This page lets people register for the site (sort of).

// Address error handing.
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);

// Set the page title and include the header file.
define ('TITLE', 'Register');
require ('templates/header.html');

// Basic HTML formatting stuff.
print '<div id="leftcontent">
    <h1>Registration Form</h1>
    <p>Register so that you can take advantage of certain features like this, that, and the other thing.</p>';

// Check if the form has been submitted.
if ( isset ($_POST['submit'])) {

    $problem = FALSE; // No problems so far.
   
    // Check for each value.
    if (empty ($_POST['username'])) {
        $problem = TRUE;
        print '<p>Please enter a username!</p>';
    }
   
    if (empty ($_POST['first_name'])) {
        $problem = TRUE;
        print '<p>Please enter your first name!</p>';
    }
   
    if (empty ($_POST['last_name'])) {
        $problem = TRUE;
        print '<p>Please enter your last name!</p>';
    }
   
    if (empty ($_POST['email'])) {
        $problem = TRUE;
        print '<p>Please enter your email address!</p>';
    }

    if (empty ($_POST['password1'])) {
        $problem = TRUE;
        print '<p>Please enter a password!</p>';
    }
   
    if ($_POST['password1'] != $_POST['password2']) {
        $problem = TRUE;
        print '<p>Your password did not match your confirmed password!</p>';
    }
   
    if (!$problem) { // If there weren't any problems...
   
        print '<p>You are now registered!<br />Okay, you are not really registered but...</p>';
       
        // Send the email.
        $body = "Thank you for registering with the Elliott Smith fan club!
Your username is {$_POST['username']}. Your password is {$_POST['password1']}.";
        mail ($_POST['email'], 'Thank you for registering at the Elliott Smith Fan Club!', $body, 'From: admin@site.com');
   
    } else { // Forgot a field.
   
        print '<p>Please try again!</p>';
       
    }

} // End of handle form IF.

// Display the form.
print '<form action="register.php" method="post"><p>';

print 'Username: <input type="text" name="username" size="20" value="' . $_POST['username'] . '" /><br />';

print 'First Name: <input type="text" name="first_name" size="20" value="' . $_POST['first_name'] . '" /><br />
Last Name: <input type="text" name="last_name" size="20" value="' . $_POST['last_name'] . '" /><br />
Email Address: <input type="text" name="email" size="20" value="' . $_POST['email'] . '" /><br />';

print 'Password: <input type="password" name="password1" size="20" /><br />
Confirm Password: <input type="password" name="password2" size="20" /><br />
<input type="submit" name="submit" value="Register!" /></p>
</form>';

// Complete the HTML formatting stuff.
print '</div>';

require ('templates/footer.html'); // Need the footer.
?>

Script Explanation:

The primary working portion of this script is lines 17-85.  Lines 17-68 check to see if the form has been submitted.  Within that group, line 20 creates a flag variable to indicate whether a problem has occurred. Lines 23-26 check to see if that a first name was entered. Lines 33-36 check to verify that a last name was entered. Lines 38-41 check to see that an email address was entered.  Lines 42-46 verify that a password was entered.  Lines 48-51 check to see if the password matches the confirmed password.  If no problems occur to this point, Lines 53-61 notify the user of a successful registration and send them a confirmation email.  If a problem does occur, Lines 62-66 notify the user of the problem.  Lines 70-83 are where the actual registration form is created and printed to the screen for viewing.

Modifications:

To prepare this script for the addition of the add_members code, delete the portion of line 55 that is in blue.
Save the script.



Tutorial
<---  1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  --->


Home Resume Page Hobbies Page InfoSec Page Projects Page Advanced Web Communications Page
Top of Page
 
©
Beth Zuber, 2005