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.
HTML form inserting user entered data to database and validating if userid is already exist.

Post method of form data

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

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

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");
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 password to the member. Here is the insert command.
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);
//echo " Inside ok loop ";
/////////////////Posting confirmation mail //////
$em=""; // 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()); } }
Login Script PHP Signup 1 Login / Logout script
Change Password

Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net



    can some one explain what is the purpose of varaible $todo? n y we have used it here? thanks in advance


    Hi can any one write the code here that how to create table in MySql data base.
    Please i Thanks advanced.


    Download the zip file, inside you can see file name dump_singup.txt . This file has sql commands to create tables.

    Post your comments , suggestion , error , requirements etc here

    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2022 All rights reserved worldwide Privacy Policy Disclaimer