diff --git a/assets/php/utils.php b/assets/php/utils.php index 95aa101..96ddd5c 100644 --- a/assets/php/utils.php +++ b/assets/php/utils.php @@ -374,7 +374,11 @@ function update_product( $query->bindValue(":new_name", $new_name); $query->bindValue(":new_description", $new_description); - $query->bindValue(":new_expiration_date", $new_expiration_date); + if ($new_expiration_date === null) { + $query->bindValue(":new_expiration_date", $new_expiration_date, PDO::PARAM_INT); + } else { + $query->bindValue(":new_expiration_date", $new_expiration_date); + } $query->bindValue(":id", $product_public_id); $query->bindValue(":owner_id", get_user_info_from_session_id("id")); diff --git a/list-products.php b/list-products.php index 045224e..0bccd64 100644 --- a/list-products.php +++ b/list-products.php @@ -8,13 +8,6 @@ if (!is_connected()) { header("location: login.php"); } -/** - * $product_public_id, - * $new_name, - * $new_description, - * $new_expiration_date - */ - if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["delete"])) { if (!delete_product($_POST["delete"])) { $erreur = "

An error happened.

\n"; @@ -35,7 +28,7 @@ if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["edit"])) { if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["edit_completed"])) { if (isset($_POST["name"]) && isset($_POST["description"]) && isset($_POST["expiration"])) { - if (!update_product($_POST["edit_completed"], $_POST["name"], $_POST["description"], $_POST["expiration"])) { + if (!update_product($_POST["edit_completed"], $_POST["name"], $_POST["description"], empty(trim($_POST["expiration"])) ? null : $_POST["expiration"])) { $erreur = "

Something went wrong. Try again later.

"; } } else { @@ -96,7 +89,7 @@ foreach (get_users_products_array() as $row) {
- +