Insert data only if record does not exist

前端 未结 3 1138
无人及你
无人及你 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:46

    $query="INSERT INTO LibraryMaster (UserID,CatalogID,ContentAddedDateTime)
    SELECT * FROM (SELECT '".$userId."', '".$catalogID."', '".$content_AddedTime."') AS tmp
    WHERE NOT EXISTS (
      SELECT CatalogID FROM LibraryMaster WHERE CatalogID = '".$catalogID."t'
     ) LIMIT 1";
    

提交回复
热议问题