Insert data only if record does not exist

前端 未结 3 1139
无人及你
无人及你 2020-12-22 05:16

I want to insert data in a table only if the record with a given CatalogID does not exist.

 $userId = $_POST[\'userId\'];
 $catalogID = $_POST[\         


        
3条回答
  •  余生分开走
    2020-12-22 05:26

    You could use this sort of function

    public function Checkrecord($catalogID )
        {
            $query="Select * from table_name where catalog_id=$catalogID ";
                      mysql_query($query,$con);
            if(mysql_num_rows($query)>0)
            {
                //report error
            }
            else
            {
                //insertQuery
            }
        }
    

提交回复
热议问题