fixed small bug for null expiration date on edition

This commit is contained in:
Louis Vallat 2019-11-16 23:21:20 +01:00
parent 7b1a2da9d5
commit e97f7ba291
2 changed files with 7 additions and 10 deletions

View File

@ -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"));

View File

@ -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 = "<p>An error happened.</p>\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 = "<p>Something went wrong. Try again later.</p>";
}
} else {
@ -96,7 +89,7 @@ foreach (get_users_products_array() as $row) {
<form method="post">
<label>Nom : </label><input type="text" name="name" value="<?php echo $edit_name; ?>">
<label>Description : </label><input type="text" name="description" value="<?php echo $edit_description; ?>">
<label>Expiration : </label><input type="calendar" name="expiration" value="<?php echo $edit_expiration; ?>">
<label>Expiration : </label><input type="date" name="expiration" value="<?php echo $edit_expiration; ?>">
<button type="publish" name="edit_completed" value="<?php echo $edit_id; ?>">Valider</button>
</form>
<?php