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.
$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 password 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()); } }
Login Script PHP Signup 1 Login / Logout script
Change Password

Scripts

Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







sana

10-05-2012

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

23-12-2014

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

23-12-2014

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




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