SQL PHP HTML ASP JavaScript articles and free scripts to download
PHP Download Scripts

Storing signup details in mysql table using PHP

Here we will collect the signup details from the member and pass it through a validation process. The member enters his/her signup details in form in the part I of the tutorial.

Post method of form data

As we have used POST method of posting data we can collect them and use in our script.

$userid=$_POST['userid'];
$password=$_POST['password'];
$password2=$_POST['password2'];
$agree=$_POST['agree'];
$todo=$_POST['todo'];
$email=$_POST['email'];
$name=$_POST['name'];
$sex=$_POST['sex'];

Data validation

In the validation we will check userid, email address are in correct format or not. We will also see if userid is already there in the signup table so we will ask the member to go for another userid. If all the validation passes then we will insert the record to the table and ask the member to login.

Sample codes to validate form input data

Also we have modified the script and using ctype_alnum function to check the userid for alphanumeric data only. You can use your own validation as per requirement. The basic intention is to explain how a signup script is to be developed. We have checked that userid is minimum 3 char length.

$status = "OK";
$msg="";

// if userid is less than 3 char then status is not ok
if(!isset($userid) or strlen($userid) <3){
$msg=$msg."User id should be =3 or more than 3 char length<BR>";
$status= "NOTOK";}
/// Alphanumeric userid only //
if(!ctype_alnum($userid)){
$msg=$msg."User id should contain alphanumeric chars only<BR>";
$status= "NOTOK";}
// Check if userid is already there
$count=$dbo->prepare("select userid from plus_signup where userid=:userid");
$count->bindParam(":userid",$userid);
$count->execute();
$no=$count->rowCount();

if($no >0 ){
$msg=$msg."User Name already exists. Choose a different User Name<br>";
$status= "NOTOK";
}
//Check of email address is already there
$count=$dbo->prepare("select email from plus_signup where email=:email");
$count->bindParam(":email",$email);
$count->execute();
$no=$count->rowCount();
if($no >0 ){
$msg=$msg."This email address is there with us. If you forgot your password you can activate it by using forgot password link. Or Please try another one<BR>";
$status= "NOTOK";
}

if ( strlen($password) < 3 ){
$msg=$msg."Password must be more than 3 char legth<BR>";
$status= "NOTOK";}

if ( $password <> $password2 ){
$msg=$msg."Both passwords are not matching<BR>";
$status= "NOTOK";}

if ($agree<>"yes") {
$msg=$msg."You must agree to terms and conditions<BR>";
$status= "NOTOK";}

Adding record to Database table

If all validations passed then we will add our data to a record in table. We will also send one welcome message with userid and passwor to the member. Here is the insert command.

if($status<>"OK"){
echo "<font face='Verdana' size='2' color=red>$msg</font><br><input type='button' value='Retry' onClick='history.go(-1)'>";
}else{ // if all validations are passed.
$password_original = $password;
$password=md5($password); // Encrypt the password before storing
$sql=$dbo->prepare("insert into plus_signup(userid,password,email,name,sex) values(:userid,:password,:email,:name,:sex)");
$sql->bindParam(':userid',$userid,PDO::PARAM_STR, 15);
$sql->bindParam(':password',$password,PDO::PARAM_STR, 32);
$sql->bindParam(':email',$email,PDO::PARAM_STR, 75);
$sql->bindParam(':name',$name,PDO::PARAM_STR);
$sql->bindParam(':sex',$sex,PDO::PARAM_STR);
if($sql->execute()){
//echo " Inside ok loop ";
$mem_id=$dbo->lastInsertId();
/////////////////Posting confirmation mail ///////////////
$em="userid@domain.com"; // Change to your email address
$headers4=$em;
$headers="";
$headers.="Reply-to: $headers4n";
$headers .= "From: $headers4n";
$headers .= "Errors-to: $headers4n";
//$headers = "Content-Type: text/html; charset=iso-8859-1n".$headers;

$content="Your login details from ****** nn";
$content .="User ID= $userid n";
$content .="Password = $password_original n";

//echo $content; $sub="Your login details";
//mail($email,"$sub",$content,$headers);
echo "<font face='Verdana' size='2' color=green>Welcome, You have successfully signed up<br><br><a href=login.php>Click here to
login</a><br></font>";
//////////////// End of posting mail ////////
}// if sql executed
else{print_r($sql->errorInfo()); }
}

Download pages of Signup script here


Google+
sana10-05-2012
can some one explain what is the purpose of varaible $todo? n y we have used it here? thanks in advance
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked



Join Our Email List
Email:  
For Email Newsletters you can trust
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer