Apologies for vague title. I currently have an edit form in which a product can be selected and the details are displayed in a form where they can be edited. Unfortunately, when edited every product in the product table is edited rather than just the product selected. To select the product i'm using where productname = productnameinput etc etc (Code below)
Database: http://prnt.sc/f4tf5g (Before an edit)
Tried adding the following WHERE statements at the end of the update query:
UPDATE product SET CategoryID = :newCatId, ProductName = :newProdName, ProductDescription = :newProdDesc, stockCount = :newStock WHERE product.ProductName = :prodname
UPDATE product SET CategoryID = :newCatId, ProductName = :newProdName, ProductDescription = :newProdDesc, stockCount = :newStock WHERE ProductName = :prodname
PHP:
// edit product in database
$query="
SELECT * FROM category
";
$result = $DBH->prepare($query);
$result->execute();
$categories = $result->fetchAll();
//we need to select all products frist
$query3 = "
SELECT * FROM product
";
$result3 = $DBH->prepare($query3);
$result3->execute();
$allProducts = $result3->fetchAll();
//When the Product is selected this function is run
if (isset($_POST['choose'])) {
$query2 = "
SELECT product.*, category.* FROM product LEFT JOIN category ON category.CategoryID = product.CategoryID WHERE product.ProductName = :prodname
";
$result2 = $DBH->prepare($query2);
$result2->bindParam(':prodname', $_POST['product_name']);
$result2->execute();
$product = $result2->fetch();
}
//When the Update button is Pressed
if (isset($_POST['update'])) {
$query4 = "
UPDATE product SET CategoryID = :newCatId, ProductName = :newProdName, ProductDescription = :newProdDesc, stockCount = :newStock WHERE product.ProductName = :prodname
";
$result4 = $DBH->prepare($query4);
$result4->bindParam(':newCatId', $_POST['newcategory']);
$result4->bindParam(':newProdName', $_POST['productName']);
$result4->bindParam(':newProdDesc', $_POST['productDescription']);
$result4->bindParam(':newStock', $_POST['stockCount']);
$result4->bindParam(':prodname', $_POST['product_name']);
$result4->execute();
}