Final Project Page 13




Projects

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



Registration Form Tutorial
Completed Registration Script


The completed register.php script should be as follows:

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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141

142
143
144
145
146
147
148
149

150
151
152
153
154
155
156
157
158
159
160
161
162

163
164
165
166
167
168
169
170
171
172
173
174
175
176
177

178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
203
204
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type"
 content="text/html; charset=iso-8859-1">
  <meta name="author" content="Beth Zuber">
  <meta name="copyright" content="2005">
  <title>Da Secret Society of DaZone</title>
  <!-- Script 8.2 - header.html -->
  <style type="text/css">

    body {
    margin:0px 0px 0px 0px;
    background:#9F9;
    background-color: #663366;
        }

    #leftcontent {   
        font-size:18px;
        margin-left:0px;
        }
       
    p,h1,pre {
        margin:0px 30px 10px 30px;
        }
   
    h1{
        font-size:24px;
        padding-top:10px;
        }
   
    h2{
        font-size:16px;
        padding-top:10px;
        }
   
    #rightcontent {
        font-size:14px;
        padding-bottom:20px;
        }
   
    body,td,th {
    font-family: Arial, Helvetica, sans-serif;
    color: #FFFFFF;
}
  </style>
</head>
<body>
<table style="width: 100%; text-align: left;" border="1" cellpadding="6"
 cellspacing="2">
  <tbody>
    <tr align="center">
      <td colspan="2" rowspan="1" style="vertical-align: top;"><span style="font-weight: bold;">
      <h1>DA Secret Society of DaZone<br>
      </h1>
      </span></td>
    </tr>
    <tr>
      <td style="width: 20%; vertical-align: top;">
      <h1>Navigation</h1>
&nbsp;<a href="index.php">Home</a><br>
&nbsp;<a href="login.php">Login</a><br>
&nbsp;<a href="register.php">Register</a><br>
      <br>
      <h2>(Temporary Navigation)</h2>
        </span></div>&nbsp;<a href="create_db.php">Create Database</a><br>
&nbsp;<a href="create_table.php">Create Table</a><br>
&nbsp;<a href="view_members.php">View Database Entries</a><br>
&nbsp;<a href="edit_entry.php">Edit Database Entries</a><br>
&nbsp;<a href="delete_entry.php">Delete Database Entries</a>
      </td><td>

<?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');

// 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>';

?>

</td>
    </tr>
    <tr> <!-- Script 8.3 - footer.html -->
        <td colspan="2" rowspan="1"><div id="rightcontent">
          <div align="center"><br />
        Created by <a href="mailto:webmaster@dazone.com">h2t2</a><br>
          Last modified 29 November 2005
          </div>
    </div></td></tr>
  </tbody>
</table>
</body>
</html>



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