asked on
<?php
// To load the config script, following command is used.
require_once('include/config.php');
// An $err variable is set assuming that there are no errors.
//Errors that occur during the registration process are checked later
$err = NULL;
// $_POST array is checked to see if all the required infoamtion is present.
//if registration informaitn is not available, then registration form is displayed
if ( (!empty($_POST["uname"])) && (!empty($_POST["uid"])) && (!empty($_POST["pwd"])) && (!empty($_POST["vwd"])) && (!empty($_POST["umail"])))
{
// Yes, the posted data is available. Escape it for use in query
$uname = mysql_real_escape_string($_POST["uname"]);
$uid = mysql_real_escape_string($_POST["uid"]);
$pwd = mysql_real_escape_string($_POST["pwd"]);
$vwd = mysql_real_escape_string($_POST["vwd"]);
$umail = mysql_real_escape_string($_POST["umail"]);
if ($_POST['submit'])
{
$uname = $_POST['uname'];
$uid = $_POST['uid'];
$pwd = $_POST['pwd'];
$vwd = $_POST['vwd'];
$umail = $_POST['umail'];
$err = ""; //default value of error string
if (!$uname)
$err = $err."Name<br>";
if (!$uid)
$err = $err."Username<br>";
if (!$pwd)
$err = $err."Password<br>";
if (!$vwd)
$err = $err."Verify Password<br>";
if (!$umail)
$err = $err."E-mail<br>";
if ($err!="")
echo "Please fill out the following fields:<br>$err";
}
if ($uname != 'a-z,A-Z') $err .= "<br/>FAIL: PLEASE ENTER A VALID NAME";
// do the password and verify password match?
if ($pwd != $vwd) $err .= "<br/>FAIL: CHOOSE AND VERIFY PASSWORDS DO NOT MATCH";
// Does the UID already exists?
$sql = "SELECT uid FROM userTable WHERE uid = '$uid' LIMIT 1";
if (!$res= mysql_query($sql)) die( mysql_error() );
$num = mysql_num_rows($res);
if ($num) $err .= "<br/>FAIL: USERNAME $uid IS ALREADY TAKEN. PLEASE CHOOSE ANOTHER USERNAME";
// If no errors were found, make unique user key
if (!$err)
{
// Make the unique user key
$uuk = md5($uid . $pwd . rand());
$sql = "INSERT INTO userTable (uname, uid, pwd, uuk, umail) VALUES ('$uname','$uid', '$pwd', '$uuk', '$umail')";
if (!$res = mysql_query($sql)) die( mysql_error() );
// store the User-ID in session array
$_SESSION["uid"] = $uid;
// check if the "REMEMBER ME" checkbox is set or not?
if (isset($_POST["rme"]))
{
remember_me($uuk);
}
// If registration is sucessfull, redirect the user to login_main page
echo "<meta http-equiv='refresh' content='0;url=\"99home.php?page=login_main\"'>";
exit;
}
// If there were errors, display the following error message
else
{
echo $err;
echo "<br/>SORRY, REGISTRATION FAILED";
}
} // Display the registratin form
?>
<form method="post">
<h2>PLEASE REGISTER</h2><p>
YOUR NAME: <input type="text" name="uname" />
<br/>CHOOSE USERNAME: <input type="text" name="uid" />
<br/>CHOOSE PASSWORD: <input name="pwd" type="password" />
<br/>VERIFY PASSWORD: <input name="vwd" type="password" />
<br/>YOUR E-MAIL: <input name="umail" /><p>
<br/><h4><input type="checkbox" name="rme" />KEEP ME LOGGED IN </h4>
<br/><input type="submit" name="submit" value="REGISTER" />
</form>