I am trying to write a script to insert values from an XML file into an SQL database.
However i can not get the script to correctly check if a value already exists in the SQL database.
heres my current code:
$result=mysql_query("SELECT * FROM `categories_description` WHERE categories_name`='$qCategory'");
if (mysql_num_rows($result) > 0){
echo "cat exists";
}
else if($qCategory != ""){
mysql_query("INSERT INTO `categories` (`categories_id`, `categories_image`, `parent_id`, `sort_order`, `date_added`, `last_modified`, `categories_status`) VALUES ('$catid', NULL, '0', NULL, NULL, NULL, '1');");
mysql_query("INSERT INTO `categories_description` (`categories_id`, `language_id`, `categories_name`, `categories_description`) VALUES ('$catid', '1', '$qCategory', '$qCategory');");
$catid +=1;
}
I have tried tons of things to get this to work, but it just doesn’t want to.
The problem I am having is if I have duplicate value it will insert it anyway.
Does anyone know how to fix this? or what it going wrong?
Many thanks in advance.
Try to fix this line first, you missed ` at the beginning of categories_name: