0

i am finding little bit difficult to check duplicate data from database using MYsql,PHP and angular.js.I am explaining my code below.

addUser.php:

<?php
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
$user_name=$request->user_name;
$user_email=$request->user_email;
$mob_no=$request->mob_no;
$login_name=$request->login_name;
$password=$request->password;
$user_status=$request->user_status;
$con = mysql_connect('localhost', 'root', 'Oditek123@');
mysql_select_db('go_fasto', $con);
$selquery = "SELECT * FROM db_user WHERE login_name='".$login_name."' and mob_no='".$mob_no."' and email='" . $user_email . "'";
$selres = mysql_query($selquery);
if(mysql_num_rows($selres ) > 0)
{
    $erresult=mysql_fetch_array($selres);
    header("HTTP/1.0 401 Unauthorized");
    $erresult['msg'] = 'This user login name or mobile no or email is already exist.';
}else{
    $qry ='INSERT INTO db_user (user_name,email,mob_no,login_name,password,user_status) values ("' . $user_name . '","' . $user_email . '","' . $mob_no . '","' .$login_name . '","' . $password . '","' . $user_status . '")';
    $qry_res = mysql_query($qry);

    $user_type = 5;
    $display_name = $user_name."_admin";
    $qry ='INSERT INTO db_Admin_Master (user_type,user_name,display_name,password) values ("' . $user_type . '","' . $login_name . '","' . $display_name . '","' .$password . '")';
    $qry_res = mysql_query($qry);



    $query='SELECT * from db_user order by user_id desc';
    $res=mysql_query($query);
    $result=mysql_fetch_array($res);
    if ($result) {
            $result['msg'] = "New User has added successfully";
        } else {
            header("HTTP/1.0 401 Unauthorized");
             $result['msg'] =  "Sorry, User could not added ";
        }
    echo json_encode($result);
}
?>

If you will check my code i am checking three column such as login_name,email and mob_no from database and checking it inside if statement.Here even if i am inserting the same data again it is not checking and else part is executing.Please help me to resolve this issue.

1
  • Can you echo mysql_num_rows($selres ) . Check that what result it provides? Commented Oct 12, 2015 at 9:49

1 Answer 1

1
$selquery = "SELECT *
    FROM db_user
    WHERE login_name='".$login_name."'
        OR mob_no='".$mob_no."'
        OR email='" . $user_email . "'";

use OR instead of AND try

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.