如何在一些预先检查后将值插入db

I want to insert some values into the db, but before inserting them into I want to make sure that there is no duplicate entry for same user against same offername and for current date

I am using this query and is working fine for userid and date

//checking for existing values
$sql11=$Db1->query("SELECT COUNT(userid) AS total FROM TABLE where userid='$userid' and date BETWEEN (NOW() - INTERVAL 1 DAY) AND NOW()");
        $temp=$Db1->fetch_array($sql11);
         $thismemberinfo['count']=$temp[total]; 
    //   
       if ($thismemberinfo['count'] >= 1 ) 
        {  WARN HERE  for duplicate entry}
        else 
        { INSERT TO DB }

I want to include offername into checking as well something like that

SELECT COUNT(userid) AS total FROM TABLE where userid='$userid' and  offername= '$offername'  date BETWEEN (NOW() - INTERVAL 1 DAY) AND NOW() 

Kindly Suggest a work around for this problem

Note:

You should not use table name as TABLE and column name date since these two words were reserved word in query. Use another name.

In order to make your query more simpler, just check both column (user_id & date) before add.

See my codes on how I would do.

//checking for existing values
$sql11=$Db1->query("SELECT COUNT(userid) AS total FROM TABLE where userid='$userid' AND offername= '$offername' AND  date BETWEEN (NOW() - INTERVAL 1 DAY) AND NOW()");
$temp = $Db1->fetch_array($sql11);
$thismemberinfo['count']=$temp['total'];  
if ($thismemberinfo['count'] >= 1) {
    // Just do nothing 
} else {
    //INSERT TO DB 
    //Current date
    $current_date = date('Y-m-d');

    $Db1->query("INSERT INTO TABLE (userid,offername,date) VALUES ('$user_id','$offername','$current_date')");
    //Table should be replace with suitable name since TABLE is a reserved word in query
}