Reputation: 11
I am facing problem in user checking from my database. I have checked the previous suggestions but that has not helped me...
My code is:
<?php include 'conn.php';
if(isset($_POST['submit']))
{
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$user=$_POST['uname'];
$email=$_POST['email'];
$depart=$_POST['department'];
$id=$_POST['id'];
$phone=$_POST['phone'];
$pass=$_POST['pass'];
$cpass=$_POST['cpass'];
$address=$_POST['address'];
$securepassword=hash('sha512', $cpass);
$chk_email="select count(*) from signup where Email='" . $email ."'";
$chk_user="select count(*) from signup where Username='" . $user . "'";
$result_mail=mysql_query($chk_email);
$result_user=mysql_query($chk_user);
$query_mail=mysql_fetch_row($result_mail);
$query_user=mysql_fetch_row($result_user);
if($cpass!==$pass)
{
header("location:setting.php");
echo $_SESSION['pass']="password not match";
return false;
}
if($query_mail[0]>0)
{
header("locatio:setting.php");
echo $_SESSION['username']="Username Already Exist";
return false;
}
if($query_user[0]>0)
{
header("location:setting.php");
echo $_SESSION['email']="Email Already Exists";
return false;
}
else
{
$qry="INSERT INTO signup (First_Name,Last_Name,Username,Email,Department,Employe_Id,Phone,Password,Address) VALUES ('$fname','$lname','$user','$email','$depart','$id','$phone','$securepassword','$address')";
if(mysql_query($qry))
{
echo "<script>window.open('success.php','_self')</script>";
header('location:index.php');
}
}
}
?>
Can anyone tell me what is the error in my code?
The previous questions and answers have not helped me. I know it is simple as a question but an error is an error.
Upvotes: 0
Views: 262
Reputation: 12233
You always insert empty values.
If $_POST['submit']
is set, you perform checks and assignments.
If not, you insert data into DB.
Because in else block you don't set value of variables $fname, $lname ...
you perform insert without data.
Remove }else{
and it should be fine
Upvotes: 1