Currently, the update only works if all the text fields are full, so the user cannot just update the productName, for example. An error does not occur, but if the rest of the text fields remain empty, the database is updated with spaces and 0. I want this to update any text fields that receive input, be it one or all, and leave the rest of the information separately if nothing is entered.
If the productName for this line is Samsung, the description of "Phone" wholesalePrice is 179.99, and I just update only the productName text box. I still want the description and wholesale price to remain unchanged. Right now, if I just update productName only then the wholesale price is displayed as 0.00 and the description is empty. I tried to use the OR operators, not the commas in the query, and any text field that I entered the information returned 0.
if(isset($_POST['id'])) {
try {
$query = "UPDATE products SET productName = :productName, description = :description, wholesalePrice = :wholesalePrice,
retailPrice = :retailPrice, category = :category, quantityOnHand = :quantityOnHand
WHERE productID = :productID";
$statement = $db->prepare($query);
$statement->bindValue(':productID', $_POST['id']);
$statement->bindValue(':productName', $productName);
$statement->bindValue(':description', $description);
$statement->bindValue(':wholesalePrice', $wholesalePrice);
$statement->bindValue(':retailPrice', $retailPrice);
$statement->bindValue(':category', $category);
$statement->bindValue(':quantityOnHand', $quantityOnHand);
$statement->execute();
$statement->closeCursor();
$page = $_SERVER['PHP_SELF'];
header('Location: ' . $_SERVER["HTTP_REFERER"] );
exit;
source
share