I want to insert data in a table only if the record with a given CatalogID
does not exist.
$userId = $_POST[\'userId\'];
$catalogID = $_POST[\
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
}
}
Create a UNIQUE
index on CatalogID
.
$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";