$userid=$_POST['userid'];
$password=$_POST['password'];
$password2=$_POST['password2'];
$agree=$_POST['agree'];
$todo=$_POST['todo'];
$email=$_POST['email'];
$name=$_POST['name'];
$sex=$_POST['sex'];
$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";}
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
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.
| 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. | |