I need some help regarding MySQL query for checking duplicate value from table using MySQL and PHP. Let me to explain my table structure and conditions
db_product_info
pro_id product_name product_code status
The above are my columns in db_product_info
table.
conditions:
1-> When table has no value the data should entry in table.
2-> In same product name only same product code will be inserted for once/multiple time in table.If input will different code for same product name (for more than one enrty
) it should be checked and return the validation message.
3- Duplicate of product_code
will be checked according to the product_name
as explained above.means for same product_name
only same product_code should entry multiple time but this product_code
should not used for any other product_name
.
Let me to explain my code below.
require_once("../include/dbconfig.php");
$result=array();
$fields=array("Product_name","status","product_code");
$tablename=PREFIX."product_info";
$values=array($_POST['product_name'],$_POST['status'],$_POST['product_code']);
$id=db_insert($tablename,$values,$fields);
if($id){
$result[0]["msg"]="Added successfully";
$result[0]['id']=$id;
echo json_encode($result);
}else{
header("HTTP/1.0 401 Unauthorized");
$result[0]["msg"]="Unable to add try again";
$result[0]["data"]=$values;
echo json_encode($result);
}
Please help me to resolve this problem.