for example there are 3 tables
1) customer
customerid, customername
2) list
listid, customerid, listname
3) product
productid, productname, listid
So here is the question:
after the customer login, they can manage its own lists and products.
when they add/update/delete the lists, i will always check if the customerid of the list belong to this customer. so no problem.
when they update/delete product, I will always to check if the listid belong to this customer, by use where and multiple table relationships.
the only problem is insert.
$sql_insert="INSERT INTO product (productsid, productname, listid) VALUES ($productid, '$productname', $listid)";
There are no where condition in insert statement that I can make sure the listid belongs to this customer. so the insert is valid.
What I did is in the beginning of the php page, I will check the listid or listid(s) which are passed to this page and will be used in this page, belong to this customer or not. This should take care of all the above problems.
But I still in the sqls about list, and sqls about update/delte product, check to see if listid belong to this customer. It is unnecessary duplication but no hurt. the database are not so big.
But I want to know is there a simple mysql built in query, that I can enforce in the sql insert statement, only allow the listid belongs to this customer to be insert into the database?
in simple words, i know customerid=3
when $sql_insert="INSERT INTO product (productsid, productname, listid) VALUES ($productid, '$productname', $listid)";
I want to make sure $listid belong to customerid 3.
Thanks!