<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html><head>
<title>Create account</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
</head>
<body>
<?php
function show_form($message) {
print "<div><h1>$message</h1><h2>Create Account</h2><p>Please complete the
form below to create your account. <!-- You will receive an
e-mail containing instructions to activate your account.
If you do not follow these directions within 48 hours,
you will need to recreate your account. --></p>
<form action=\"$_SERVER[PHP_SELF]\" method=\"post\">
<div><input type=\"hidden\" name=\"submitted\" value=\"1\" /></div>
<h3>Username</h3>
<p>Username <input type=\"text\"
name=\"username\" maxlength=\"15\" value=\"$_POST[username]\" /></p>
<p>Your username will be used to login to your account and make changes.</p>
<!--
<h3>E-mail Address</h3>
<p><E-mail Address
<input type=\"text\" name=\"email1\" value=\"$_POST[email1]\" />
<label for=\"email2\">Confirm E-mail Address:</label>
<input type=\"text\" name=\"email2\" value=\"$_POST[email2]\" /></p>
<p>The e-mail address you enter must be valid. Instructions to
activate your account will be sent to the e-mail address provided.
You must keep this address current. Any accounts with invalid
e-mail addresses are subject to removal without working.
We do not sell our list to anyone. Read more about our privacy policy.</p>
-->
<h3>Password</h3><p>
Password <input type=\"password\" name=\"pass1\" value=\"$_POST[pass1]\"/>
Confirm Password
<input type=\"password\" name=\"pass2\" value=\"$_POST[pass2]\"/>
</p><p>The password you enter will be used to access your account. It
must be more than 5 characters and cannot be your username.</p>
<p><input type=\"submit\" value=\"Create Account\" /></p></form></div>";
}
function process_form() {
$username=trim($_POST['username']);
$pass1=trim($_POST['pass1']);
$pass2=trim($_POST['pass2']);
if(strlen($username)<6) {
return "Username is too short.";
}
if(! ($pass1 == $pass2)) {
return "Passwords do not match.";
}
$pass=$pass1;
if($pass == $username) {
return "Your username can not be your password.";
}
if(strlen($pass)<6) {
return "Password is too short.";
}
$sha_pass=sha1($pass);
$db=mysql_connect('localhost:6033','krichel','');
$query="INSERT INTO beer_shop.users VALUES ('','$username','$sha_pass')";
$result=mysql_query($query);
$error=mysql_error();
if($error == "Duplicate entry '$username' for key 2") {
return "Sorry: Username $username is already taken, choose another.";
}
else {
print "<h1>Thank you for registering with us!</h1>";
}
}
if($_POST['submitted']) {
$error=process_form();
if($error) {
show_form($error);
}
}
else {
show_form('');
}
?>
<p>
<a href="http://validator.w3.org/check?uri=referer"><img
style="border: 0pt"
src="/valid-xhtml10.png"
alt="Valid XHTML 1.0!" height="31" width="88" /></a>
</p>
</body>
</html>