javascript - PHP Validation from database -
i working on project , stuck on registration page. want verify if:
- the mobile number exists.
- the username exists.
- the email id exists.
currently in code have added validation mobile number , working fine. username , email part not understanding how implement it. please me out problem.
here code.
<?php $msg = ''; if(isset($_post['register'])) { $uname = (!empty($_post['username']))?$_post['username']:null; $pass = (!empty($_post['pass']))?$_post['pass']:null; $cpass = (!empty($_post['cpass']))?$_post['cpass']:null; $fname = (!empty($_post['fname']))?$_post['fname']:null; $lname = (!empty($_post['lname']))?$_post['lname']:null; $email = (!empty($_post['email']))?$_post['email']:null; $mobile = (!empty($_post['mobile']))?$_post['mobile']:null; if($uname == '' || $pass == '' || $cpass == '' || $fname == '' || $lname == '' || $email == '' || $mobile == ''){ $msg = "<font color='red'>fields cannot empty</font>"; }else if(strlen($uname)<5){ $msg = "<font color='red'>username must @ least 5 characters long</font>"; }else if(strlen($pass)<6 && strlen($cpass)<6){ $msg = "<font color='red'>password must @ least 6 characters long</font>"; }else if($pass != $cpass){ $msg = "<font color='red'>passwords not matching</font>"; }else if(!is_numeric($mobile)){ $msg = "<font color='red'>mobile number should contain numbers</font>"; }else if(strlen($mobile)<10){ $msg = "<font color='red'>mobile number should @ least 10 characters long</font>"; }else{ $query = "select user_mobile user_reg user_mobile = '".$mobile."'"; $query1 = mysql_query($query) or die(mysql_error()); $num_rows = mysql_num_rows($query1); $row = mysql_fetch_array($query1); if($num_rows > 0) { $msg = "<font color='red'>mobile number exists. please try again...</font>"; } else{ $str = "insert user_reg(user_email, user_uname, user_pass, user_fname, user_lname, user_mobile)values('$email','$uname','$pass','$fname','$lname','$mobile')"; $sql = mysql_query($str) or die(mysql_error()); if($sql){ $msg = "<font color='green'>regstration successfull. please login use account.</font>"; }else{ $msg = "<font color='red'>sorry.. there errors. please fix them before continue.</font>"; } } } } ?>
html part.
<div class="reg-box"><br /> <center> <?php echo $msg; ?> </center> <form method="post" action="<?php echo $_server['php_self']; ?>"> <div> <label>username</label> <input type="text" name="username" value="" class="a-text" /> </div> <div> <label>password</label> <input type="password" name="pass" value="" class="a-text" /> </div> <div> <label>confirm password</label> <input type="password" name="cpass" value="" class="a-text" /> </div> <div> <label>first name</label> <input type="text" name="fname" value="" class="a-text" /> </div> <div> <label>last name</label> <input type="text" name="lname" value="" class="a-text" /> </div> <div> <label>email</label> <input type="email" name="email" value="" class="a-text" /> </div> <div> <label>mobile</label> <input type="text" name="mobile" value="" class="a-text" maxlength="10" /> </div> <input type="submit" name="register" value="register" class="button" id="button-left" /> </form> </div>
what should add username , email validation? please me out friends.
@jha, seems quite confused. yh know, kind of wierd. if go by:
<?php $msg = ''; if (isset($_post['register'])) { $uname = (!empty($_post['username'])) ? $_post['username'] : null; $pass = (!empty($_post['pass'])) ? $_post['pass'] : null; $cpass = (!empty($_post['cpass'])) ? $_post['cpass'] : null; $fname = (!empty($_post['fname'])) ? $_post['fname'] : null; $lname = (!empty($_post['lname'])) ?$_post['lname'] : null; $email = (!empty($_post['email'])) ?$_post['email'] : null; $mobile = (!empty($_post['mobile'])) ?$_post['mobile'] : null; if ($uname == '' || $pass == '' || $cpass == '' || $fname == '' || $lname == '' || $email == '' || $mobile == '') { $msg = "<font color='red'>fields cannot empty</font>"; } else if (strlen($uname) < 5) { $msg = "<font color='red'>username must @ least 5 characters long</font>"; } else if (strlen($pass) < 6 && strlen($cpass) < 6) { $msg = "<font color='red'>password must @ least 6 characters long</font>"; } else if ($pass != $cpass) { $msg = "<font color='red'>passwords not matching</font>"; } else if (!is_numeric($mobile)) { $msg = "<font color='red'>mobile number should contain numbers</font>"; } else if (strlen($mobile) < 10) { $msg = "<font color='red'>mobile number should @ least 10 characters long</font>"; } else { //query mobile validation $m_sql = "select user_mobile user_reg user_mobile = '".$mobile."'"; $m_query = mysql_query($m_sql) or die(mysql_error()); $m_num_rows = mysql_num_rows($m_query); $m_row = mysql_fetch_array($m_query); //query username validation $u_sql = "select user_mobile user_reg user_mobile = '".$uname."'"; $u_query = mysql_query($u_sql) or die(mysql_error()); $u_num_rows = mysql_num_rows($u_query); $u_row = mysql_fetch_array($u_query); //query email validation $e_sql = "select user_email user_reg user_mobile = '".$email."'"; $e_query = mysql_query($e_sql) or die(mysql_error()); $e_num_rows = mysql_num_rows($e_query); $e_row = mysql_fetch_array($e_query); if ($m_num_rows > 0) { $msg = "<font color='red'>mobile number exists. please try again...</font>"; } else if ($u_num_rows > 0) { $msg = "<font color='red'>username exists. please choose unique one...</font>"; } else if ($e_num_rows > 0) { $msg = "<font color='red'>email exists. please choose unique one...</font>"; } else { $str = "insert user_reg(user_email, user_uname, user_pass, user_fname, user_lname, user_mobile)values('$email','$uname','$pass','$fname','$lname','$mobile')"; $sql = mysql_query($str) or die(mysql_error()); if ($sql) { $msg = "<font color='green'>regstration successfull. please login use account.</font>"; } else { $msg = "<font color='red'>sorry.. there errors. please fix them before continue.</font>"; } } } }
?>
Comments
Post a Comment