Hi there,
my table fields are.
id mobile email date.
Here mobile and email should be unique.

How to check exisitng email and existing mobile number in php.
i want to put the message separately.
this is what i done .

  public function createUser($name, $email, $password, $mobile_no) 
        $response = array();        


                    $password_hash = sha1($password);   
                    $position1 = "Customer";
                    $rolecodeis = "2";
                    $comp = "Dealssante"; 
                    $today = date('Y-m-d');

                    $stmt1 = $this->conn->prepare("INSERT INTO customer_master(customer_name, customer_email, customer_mobileno, created_date, position) values(?, ?, ?, ?, ?)");
                    $stmt1->bind_param("sssss", $name, $email, $mobile_no, $today, $position1); 
                    $result = $stmt1->execute();            
                    $customerinsertid = $this->conn->insert_id;
                    $otp = mt_rand(100000, 999999);             
                    // sms scripts will comes here 

                    $stmt = $this->conn->prepare("INSERT INTO np_system_users(u_password, u_rolecode, person_row_id, firstname, email, mobile, company, createdat, position, onetime_password) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
                    $stmt->bind_param("sssssssssi", $password_hash, $rolecodeis, $customerinsertid, $name, $email, $mobile_no, $comp, $today, $position1, $otp); 
                    $result1 = $stmt->execute();

                    if ($result == 1) 
                        return USER_CREATED_SUCCESSFULLY;
                        return USER_CREATE_FAILED;

            return MOBILE_EXISTED;

            return USER_ALREADY_EXISTED;

        return $response;   


you have to perform a select query inside the methods isUserExistscustomer() and $this->isUserExistsmobile() and return boolean TRUE or FALSE.

For example:

public function isUserExistsmobile($mobile_no)
    $stmt = $this->conn->prepare("SELECT id FROM np_system_users WHERE customer_mobileno = ?");
    $stmt->bind_param('s', $mobile_no);

    return $stmt->num_rows > 0 ? TRUE : FALSE;

Do the same for the email. The mobile number should be trimmed, to avoid leading and trailing spaces that could trick the system and allow duplicates:

$mobile_no = trim($mobile_no);

You should also remove spaces, dashes, dots inside the string, i.e. convert 555-123 231 to 555123231 and you should match prefixes which can be expressed in two ways, for example the international prefix for USA is 001 which can be shorted to +1.

So here you should decide if the client can insert prefixes manually or by a dropdown menu (select tag), and if you want to reject the input which is not composed just by digits.

Regarding the trim() function the same applies to email addresses, where you should lower the case to avoid values like abc@some.tld and Abc@some.tld. You can use mb_strtolower() or the MySQL function LOWER(), however this depends also on the charset assigned to the table column:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.