如何在插入php之前检查数据库中是否存在当前手机号 存在则不写入,不存在则继续执行


<?php
include_once("../config.php");
$uid = $_GET['uid'];
$lxr = $_GET['lxr'];
$tel = $_GET['tel'];
$bmm = $_GET['bmm'];
//$gzms = $_GET['gzms'];
$t=time();
//$wxid = $_GET['wxid'];
$uid = str_ireplace($search, '', $uid);
$lxr = str_ireplace($search, '', $lxr);
$tel = str_ireplace($search, '', $tel);
$bmm = str_ireplace($search, '', $bmm);
$bm=intval($_GET['bm']);
$wxid=intval($_GET['wxid']);


if($wxid ==0){

    $sql="insert into user (openid, juese, ming, tel, username, tbsj) values 
                            ('$uid', '$bmm',  '$lxr', '$tel','$tel', $t)";
    //$sql = str_replace(PHP_EOL, '', $sql); 
    mysqli_query($con,$sql);
    $id = mysqli_insert_id($con);
    if($id){
         $result = '{"status":"1","msg":"ok"}';
         $ok = true;
    }else{
         $result = '{"status":"0","msg":"提交失败,请重试"}';
         $ok = false;
    }
    echo $result;
}
?>

你在插入数据前 用查询语句 查询一下 这个手机号是否存在。如果存在就跳过,不存在就执行插入语句!


    $sql="select count(*) from user where tel = $tel;

    mysqli_query($con, $sql);

你这是插入,不是更新。更新才可以判断是否phone字段有没有值。插入就是真加一条数据原先本没数据你能理解吗?