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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
<?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...
// modified Script 12.5 -
add_member.php
// This script
adds a member's data to the database.
// Connect and
select.
if ($dbc
= @mysql_connect ('localhost', 'username', 'password')) {
if (!@mysql_select_db ('mymembers')) {
die ('<p>Could not select
the database because: <b>' . mysql_error()
.'</b></p>');
}
} else {
die ('<p>Could not connect to MySQL because:
<b>' . mysql_error() .'</b></p>');
}
// Define the
query.
$query =
"INSERT INTO member_list (member_id, username, first_name,
last_name, email_addy, password, date_reg)
VALUE (0,
'{$_POST['username']}','{$_POST['first_name']}','{$_POST['last_name']}',
'{$_POST['email_addy']}','{$_POST['password']}', NOW())";
// Execute the
query.
if
(@mysql_query ($query)) {
print '<p>The member's data has been
added.</p>';
} else {
print "<p>Could not add the member's data
because: <b>" . mysql_error() .
"</b>. The query was $query.</p>";
}
mysql_close();
// End
modified Script 12.5 - add_member.php
print '<p>You are now registered.</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.
?>
|