I have two tables, CATEGORIES and PRODUCTS, with category_id as a foreign key in PRODUCTS. How can I update a field in PRODUCTS table that automatically update the foreign key too? I want to update the category by category_name with html select box.
This the function updateProduct in my CRUD.php
public function updateProduct($id, $product_name, $product_price, $category_name) {
$sql = "UPDATE products INNER JOIN categories ON products.category_id = categories.category_id SET product_name = '$product_name', product_price = '$product_price' category_name = '$category_name' WHERE product_id = $id";
$stmt = $this->conn->prepare($sql);
$stmt->execute();
return true;
}