Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,208,746 members, 8,003,618 topics. Date: Friday, 15 November 2024 at 04:15 PM

Help With PHP Registration Code - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / Help With PHP Registration Code (938 Views)

Creating An Alumni Site With Php And Mysql / Designing A Site With Php And Oracle Tutorial (Oracle 10G) / Controlling Cpanel With Php Scripts To Create Email, Dbase, Subdomains: (2) (3) (4)

(1) (Reply)

Help With PHP Registration Code by geniusng(m): 4:07am On Nov 12, 2012
Please help me
When I register with a username that is already existing on the database, it bring message 2 messages:
(1.) Successful Registration! stanislaus, Check your email (calvarylove2002@yahoo.com) to activate your account! (2.) Username already taken!
Though it will not submit to database.Apart from this, every other things works fine.

Thank you


<?php
session_start();
if($_GET[status]=="notamember"wink
$msgs="<b> Hey! Welcome. You MUST be a REGISTERED MEMBER to enjoy the benefits of this site.</b>";

$submit = $_POST["submit"];

//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 = date("Y-m-d"wink;
if ($submit)
{

//open database
$connect = mysql_connect ("localhost","iiocafri_users","password"wink or die ("Could not connect"wink;
mysql_select_db("iiocafri_members"wink or die ("Couldn't find the database"wink;

$namecheck = mysql_query("SELECT username FROM iiocafri_users WHERE username='$username'"wink;
$count = mysql_num_rows($namecheck);

if ($count!=0)
{
$mymessage="Username already taken!";
}


//check for existence
if ($firstname&&$lastname&&$email&&$password&&$confirmpassword)

{
if ($password==$confirmpassword)
{
//check char length
if (strlen($username)>20||strlen($firstname)>20||strlen($lastname)>20)
{
$urmessage="Length of username or first name or lastname is too long, it must no be longer than 20";
}
else
{

//check password length
if (strlen($password)>10||strlen($password)<6)
{
$urmessage="Password must be between 6 and 10 characters";
}
else

//register the user!

//encrypt password
$password = md5($password);
$confirmpassword = md5($confirmpassword);

//generate random number for activation process
$random = rand(23456789,98765432);

$queryreg = mysql_query("INSERT INTO iiocafri_users VALUES ('','$firstname','$lastname','$address','$phone1','$phone2','$email','$username','$password','$random','$activated','$date') "wink;

$lastid = mysql_insert_id();

{
//send activation email
$to = $email;
$subject = "Activate your account!";
$headers = "From: info@africa.com";

$body = "
Hello $firstname,\n\n
You need to activate your account with the link below:\n\n
http://africa.com/activate.php?id=$lastid&code=$random\n\nThanks!";

//function to send email
mail($to, $subject, $body, $headers);

$urmessage="Successful Registration! $firstname, Check your email ($email) to activate your account!";
}
}
}
else
$urmessage="Your passwords do not match!";
}
else
$urmessage="** Please fill in <b>ALL</b> fields!";
}
?>
Re: Help With PHP Registration Code by Nobody: 5:29am On Nov 12, 2012
I HAVE RE-WRITE THE CODE FOR YOU (I NO GUARANTEE ANYTHING OH) NOTE: I NEVER TEST AM TOO grin BUT IT SHOULD WORK!


<?PHP
//// YOUR CONECTION //////////////////////////////

$con=mysql_connect("localhost","",""wink or die("System busy, try again later"wink;
mysql_select_db("test"wink or die("Kindly wait some minutes, and try again later"wink;

//// 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"wink;
$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"wink;
$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>

(1) (Reply)

Pls Take A Look At My Forum And Advice Me On How I Can Make It Better / Google Introduces Google+ Comments To Replace Default Blogger Commenting Sytem / Wordpress Is By Far Better Than Blogger

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 39
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.