Forum Moderators: coopster
<?php
$submit = $_POST['submit'];
//form data
$fullname = strip_tags($_POST['fullname']);
$username = strtolower(strip_tags($_POST['username']));
$password = strip_tags($_POST['password']);
$repeatpassword = strip_tags($_POST['repeatpassword']);
$date = date("Y-m-d");
if ($submit)
{
// Connect to the database
$connect = mysql_connect("localhost","root","") or die ("Couldn't connect");
mysql_select_db("rentals") or die ("Couldn't find database");
$namecheck = mysql_query("SELECT username FROM users WHERE username='$username'");
$count = mysql_num_rows($namecheck);
if ($count!=0)
{
die("Username already exists!"); // This wants to be displayed further down
}
// Check for existance
if ($fullname&&$username&&$password&&$repeatpassword)
{
if ($password==$repeatpassword)
{
if (strlen($fullname)>25 || strlen($username)>25)
{
echo "The maximum length of fullname / username is 25 characters.";
}
else
{
// Check password length
if (strlen($password)>25 || strlen($password)<6)
{
echo "Password must be between 6 and 25 characters long";
}
else
{
// Register the user
// Encrypt password
$password = md5($password);
$repeatpassword = md5($repeatpassword);
$queryreg = mysql_query("INSERT INTO users VALUES ('','$fullname','$username','$password','$date')");
header('location: registration_success.php');
}
}
}
else
echo "Your passwords do not match!";
}
else
echo "Please fill in all fields.";
}
?>
<!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=utf-8" />
<link rel="stylesheet" type="text/css" href="css/stylesheet.css">
<title></title>
</head>
<body>
<div id="wrapper">
<div id="container">
<div id="header">
<div id="user_box">
</div>
</div>
<div id="navigation">
<ul>
<li><a href="css/index.php">Home</a></li>
</ul>
</div>
<div id="spacer_horizontal"></div>
<div id="left_panel"><img src="images/feather-left-side-banner.jpg" width="152" height="495" /></div>
<div id="centre_panel">
<?php echo "<h1>Register</h1>"; ?>
<form action="register.php" method="POST">
<table>
<tr>
<td>
Your full name:
</td>
<td>
<input type="text" name="fullname" value="<?php echo $fullname; ?>">
</td>
</tr>
<tr>
<td>
Choose a username:
</td>
<td>
<input type="text" name="username" value="<?php echo $username; ?>">
</td>
</tr>
<tr>
<td>
Choose a password:
</td>
<td>
<input type="password" name="password">
</td>
<tr>
<td>
Repeat your password:
</td>
<td>
<input type="password" name="repeatpassword">
</td>
</tr>
</tr>
</table>
<p>
<input type="submit" name="submit" value="Register"/>
</div>
<div id="right_panel"><img src="images/feather-right-side-banner.jpg" width="152" height="495" /></div>
</div>
<div id="spacer_horizontal_bordered_top"></div>
<div id="bottom_panel">
<ul>
<li><a href="css/index.php">Home</a></li>
<li><a href="#">Search</a></li>
</div>
<div id="spacer_horizontal_bordered_bottom"></div>
<div id="footer">
Web Design Services<br />
<a href="http://jigsaw.w3.org/css-validator/check/referer" class="nav">W3C Compliant CSS</a> | <a href="http://validator.w3.org/check?uri=referer" target="_blank" class="nav">W3C Compliant XHTML</a><br />
<?php
echo date("l, dS F Y, h:ia" ,time());
?>
</div>
</div>
</body>
</html>
<?php echo $fullname; ?>etc.
<?php echo htmlentities($fullname); ?>