hi i cannot update a table which has foreign keys on it. in this table, instead of displaying the primary keys of the foreign key, i choose to display their names: this is a simple diagram: Here are my foreign tables:
Size Table:
sId sName
1 1x1
2 2x2
Brand Table:
bId bName
1 brand1
2 brand2
Supplier Table:
sId sName
1 supp1
2 supp2
So here is my Warehouse Table using a join statement:
pId pName pSize pBrand pSupplier
1 prod1 1x1 brand1 supp1
2 prod2 2x2 brand2 supp2
here is my edit in php and mysql form:
########### EDIT PRODUCT
if(isset($_POST['editproduct'])){
$product_id=$_POST["product_code"];
$product_name=$_POST["product_name"];
$size_name=$_POST["size_name"];
$brand_name=$_POST["brand_name"];
$supplier_name=$_POST["supplier_name"];
$sql = "UPDATE warehouse SET
product_name='$product_name'
,size_id='$size_id'
,brand_id='$brand_id'
,supplier_id='$supplier_id'
WHERE
product_code='$product_code'";
$result=mysql_query($sql,$connection) or die(mysql_error());
header("location: warehouse.php");
} ?>
the weird thing is that the first try i edit the table it does not error. but for the second time, it prompts me the error of foreign key constraint, :(
i have a feeling that because i use a join statement in my warehouse table, that conflicts my update query since the one i am updating is the primary key and i only display its name.