I HAVE RE-WRITE THE CODE FOR YOU (I NO GUARANTEE ANYTHING OH) NOTE: I NEVER TEST AM TOO
BUT IT SHOULD WORK!
<?PHP
//// YOUR CONECTION //////////////////////////////
$con=mysql_connect("localhost","","" or die("System busy, try again later"
mysql_select_db("test" or die("Kindly wait some minutes, and try again later"
//// YOUR CONECTION //////////////////////////////
/// FUNCTIONS YOU WILL NEED
function checkUniqueEmail($email) /// this is to check if the email is in your database
{
$query="SELECT email FROM TABLENAME WHERE email='{$email}'"; //// change TABLENAME to your dabase tablename
$sendQuery=mysql_query($query) or die("Please try again later"
$outCome=mysql_num_rows($sendQuery);
return $outCome;
}
function checkUniqueUser($username) /// this is to check if the username is in your database
{
$query="SELECT username FROM TABLENAME WHERE username='{$username}'"; //// change TABLENAME to your dabase tablename
$sendQuery=mysql_query($query) or die("Please try again later"
$outCome=mysql_num_rows($sendQuery);
return $outCome;
}
function sendMails($to,$title,$msg,$from,$reply_to)
{
$headers = "From: " . strip_tags($from) . "\r\n";
$headers .= "Reply-To: ". strip_tags($reply_to) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/plain; charset=ISO-8859-1\r\n";
mail($to,$title,$msg,$headers);
}
function genRandomNo($length=10) {
$randomNumber = '';
$possible = '0123456789';
$i = 0;
while ($i < $length) {
$randomNumber .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
$i++;
}
return $randomNumber;
}
?>
<?PHP
if (isset($_POST['Registration'])){
//form data
$firstname = strtolower(strip_tags($_POST['firstname']));
$lastname = strtolower(strip_tags($_POST['lastname']));
$address = strtolower(strip_tags($_POST['address']));
$phone1 = strip_tags($_POST['phone1']);
$phone2 = strip_tags($_POST['phone2']);
$email = strtolower(strip_tags($_POST['email']));
$username = strtolower(strip_tags($_POST['username']));
$password = strip_tags($_POST['password']);
$confirmpassword = strip_tags($_POST['confirmpassword']);
$date = strtotime(date("Y-m-d" )); // This is better because you might need to compare the time in future
$random = genRandomNo(); /// This is the generated random number
$array=array();
if(
empty($firstname) ||
empty($username) ||
empty($lastname) ||
empty($email) ||
empty($password) ||
empty($address) ||
empty($confirmpassword) ||
empty($phone1)
)
{
$array[]="Fill all field to Register with Us";
}
if($password != $confirmpassword)
{
$array[]="Password not Matched";
}
if((strlen($password) < 6) || (strlen($password) > 10))
{
$array[]="Password must be between 6 and 10 characters";
}
if(checkUniqueEmail($email))
{
$array[]="The Email supply already exist on our system, kindly login with your information if you are already a member, or try again if you made a mistake";
}
if(checkUniqueUser($username))
{
$array[]="The username already taken, please select another one";
}
if(count($array))
{
$errorDey=1;
}
else{
$errorDey=0;
$password=hash('sha256',$password);
$query="INSERT INTO TABLENAME SET
firstname='{$firstname}',
username='{$username}',
lastname='{$lastname}',
email='{$email}',
password='{$password}',
address='{$address}',
phone1='{$phone1}',
phone1='{$phone1}',
random='{$random}',
date='{$date}'";
$send=mysql_query($query) or die();
if(mysql_affected_rows()){
$RegistrationFinish = 1;
//send activation email
$message="Dear {$firstname} {$lastname},";
$message .=""."\r\n";
$message .="You need to activate your account with the link below"."\r\n";
$message .=""."\r\n";
$message .=" http://africa.com/activate.php?id={$lastid}&code={$random}"."\r\n";
$message .=""."\r\n";
$message .=""."\r\n";
$message .="http://africa.com"."\r\n";
$title = "Activate your account!";
$from='info@africa.com';
$replyTo='info@africa.com';
sendMails($email,$title,$message,$from,$replyTo);
}
}
}
?>
<?PHP
//// error message
if(isset($errorDey)){
foreach($array as $var){ echo $var . "<br />";}
}
//// sucess message
if(isset($RegistrationFinish)){
echo "<font color='red'>Successful Registration! $firstname, Check your email ($email) to activate your account!</font>";}
?>
<form action="" method="post">
<table>
<tr>
<td>First Name: </td>
<td><input type='text' name='firstname' value='' /></td>
</tr>
<tr>
<td>Last Name: </td>
<td><input type='text' name='lastname' value='' /></td>
</tr>
<tr>
<td>Address: </td>
<td><input type='text' name='address' value='' /></td>
</tr>
<tr>
<td>Email: </td>
<td><input type='text' name='email' value='' /></td>
</tr>
<tr>
<td>Phone: </td>
<td><input type='text' name='phone1' value='' /></td>
</tr>
<tr>
<td>Phone: </td>
<td><input type='text' name='phone1' value='' /></td>
</tr>
<tr>
<td>Username: </td>
<td><input type='text' name='username' value='' /></td>
</tr>
<tr>
<td>Password: </td>
<td><input type='password' name='password' value='' /></td>
</tr>
<tr>
<td>Password Again: </td>
<td><input type='password' name='password1' value='' /></td>
</tr>
<tr>
<td></td>
<td><input type='submit' name='Registration' value='Submit' /> </td>
</tr>
</table>