Re: Super Lost!
Posted: Thu Jan 13, 2011 2:12 am
True, will my website need Verisign? The only thing users will be purchasing is an account upgrade.
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
I guess...Christopher wrote:I assume that you will use their email as their unique ID. Ao your user schema might look something like this:
id INT
active CHAR(1) DEFAULT 'Y'
email VARCHAR
password VARCHAR
first_name VARCHAR
last_name VARCHAR
address VARCHAR
city VARCHAR
state VARCHAR
zip_code VARCHAR
country VARCHAR
education VARCHAR
phone_number VARCHAR
date_of_birth VARCHAR or DATE
With id as the PRIMARY KEY and an INDEX on email
You will need to pick appropriate lengths for these fields. If you are storing the password as a hash then the hash length will determine the size of that field. Also, education may include multiple data points if it is not simple the maximum education level. If so you would need a user_education table to store those entries.
Have a go at a MySQL schema and then tell us a little about how you want registration to work.
Code: Select all
<?
include 'config.php';
if(isset($_POST['submit']))
{
$first = addslashes(trim($_POST['firstname']));
$surname = addslashes(trim($_POST['surname']));
$username = addslashes(trim($_POST['username']));
$email = addslashes(trim($_POST['email']));
$pass = addslashes(trim($_POST['password']));
$conf = addslashes(trim($_POST['confirm']));
$activ = addslashes(trim($_POST['activation']));
$date = date("d/m/y");
$errormsg='Errors:\n';
# pop up window if password is not equal to confirmed password
if ( $_POST['password'] == $_POST['confirm'] )
{$error1=0;}else{
$error1=1;
$errormsg=$errormsg.'Passwords were not the same\n';
#echo '<script>alert("Your passwords were not the same, please enter the same password in each field.");</script>';
#echo '<script>history.back(1);</script>';
#exit;
}
# encode the password
$password = md5($pass);
# pop up window if any field was left empty
if ((((( empty($first) ) || ( empty($surname) ) || ( empty($username) ) || ( empty($email) ) || ( empty($password) )))))
{
$error2=1;
$errormsg=$errormsg.'One or more fields were left empty\n';
#echo '<script>alert("One or more fields was left empty, please try again.");</script>';
#echo '<script>history.back(1);</script>';
#exit;
}else{$error2=0;}
# pop up window if an invalid email address was entered
if((!strstr($email , "@")) || (!strstr($email , ".")))
{
$error3=1;
$errormsg=$errormsg.'Invalid email address\n';
#echo '<script>alert("You entered an invalid email address. Please try again.");</script>';
#echo '<script>history.back(1);</script>';
#exit;
}else{$error3=0;}
# check if username is already in use in the database and pop up if there is
$q = mysql_query("SELECT * FROM Users WHERE Username = '$username'") or die(mysql_error());
if(mysql_num_rows($q) > 0)
{
$error4=1;
$errormsg=$errormsg.'Username already in use\n';
#echo '<script>alert("The username you entered is already in use, please try again.");</script>';
#echo '<script>history.back(1);</script>';
#exit;
}else{$error4=0;}
# check if activation code is correct
$q1 = mysql_query("SELECT code FROM codes WHERE id = 1") or die(mysql_error());
$q2 = mysql_query("SELECT code FROM codes WHERE id = 2") or die(mysql_error());
$row1 = mysql_fetch_array($q1);
$row2 = mysql_fetch_array($q2);
if ( $_POST['activation'] == $row1['code'] ){
$code = 0;
$error5=0;
}elseif ( $_POST['activation'] == $row2['code'] ){
$code = 9;
$error5=0;
}else
{
$error5=1;
$errormsg=$errormsg.'Activation code incorrect\n';
#echo '<script>alert("Your activation code was incorrect, please enter the correct code to register.");</script>';
#echo '<script>history.back(1);</script>';
#exit;
}
if ($error1 || $error2 || $error3 || $error4 || $error5){
echo '<script>alert("'.$errormsg.'");</script>';
echo '<script>history.back(1);</script>';
exit;
}
$name = $first . ' ' . $surname;
$query = mysql_query("INSERT INTO Users (Username, Password, Name, Email, Date, Level) VALUES ('$username','$password','$name','$email','$date','$code')") or die(mysql_error());
if($query)
{
echo ' <html>
<head>
<title>Success</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="success">
<p>Success! You are now a registered member</p>
<p>Click <a href="login.php">here</a> to login</p>
</div>
</body>
</html>
';
} else {
echo '
<html>
<head>
<title>Error</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="error">
<p>We are sorry, there appears to be a problem with our script at the moment.</p>
<p>Your data was not lost. Username: '.$username.' | Password: '.$pass.' | Email: '.$email.' | Full name: '.$name.'</p>
<p>Please try again by clicking <a href="login.php">here</a>.</p>
</div>
</body>
</html>
';
}
} else {
?>
<html>
<head>
<title>Register</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="wrapper">
<div id="head">the registration page</div>
<br>
<div id="main">
<p>Welcome to the registration, fill out the form below and hit Submit. All fields are required,so fill them all out! </p>
<form action="<?= $_SERVER['PHP_SELF'] ?>" method="post">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr class="firstRow">
<td width="50%">First name </td>
<td width="50%"><input name="firstname" type="text" class="textBox" id="firstname"></td>
</tr>
<tr class="secondRow">
<td>Surname</td>
<td><input name="surname" type="text" class="textBox" id="surname"></td>
</tr>
<tr class="firstRow">
<td>Email Address </td>
<td><input name="email" type="text" class="textBox" id="email"></td>
</tr>
<tr class="secondRow">
<td>Username</td>
<td><input name="username" type="text" class="textBox" id="username"></td>
</tr>
<tr class="firstRow">
<td>Password</td>
<td><input name="password" type="password" class="textBox" id="password"></td>
</tr>
<tr class="secondRow">
<td>Confirm Password </td>
<td><input name="confirm" type="password" class="textBox" id="confirm"></td>
</tr>
<tr class="firstRow">
<td>User Activation Code *</td>
<td><input name="activation" type="password" class="textBox" id="activation"></td>
</tr>
<tr class="secondRow">
<td>Register</td>
<td><input name="submit" type="submit" class="textBox" value="Submit"></td>
</tr>
<tr class="firstRow">
<td>* Activation codes assessed by your administrator</td>
<td>If you are already registered click <a href="login.php">here</a> to login</td>
</tr>
</table>
</form>
</div>
</div>
</body>
</html>
<?
}
?>