Fix the duration set error

This commit is contained in:
Gregory Trolliet 2020-11-25 22:35:28 +01:00
parent 3fbeb06948
commit 06de0eb561
2 changed files with 3 additions and 4 deletions

View file

@ -29,7 +29,6 @@ if (empty($_POST)) {
</div> </div>
<?php <?php
} else { } else {
$length = 6; $length = 6;
$token = bin2hex(random_bytes($length)); $token = bin2hex(random_bytes($length));
if (isset($_POST['fsize']) && is_numeric($_POST['fsize'])) { if (isset($_POST['fsize']) && is_numeric($_POST['fsize'])) {
@ -42,7 +41,7 @@ if (empty($_POST)) {
} else { } else {
$text = ''; $text = '';
} }
if (isset($_POST['fduration']) && in_array($_POST['fduration'], DataBase::OPTIONS_DURATION)) { if (isset($_POST['fduration']) && key_exists($_POST['fduration'], DataBase::OPTIONS_DURATION)) {
$duration = $_POST['fduration']; $duration = $_POST['fduration'];
} else { } else {
$duration = DataBase::DEFAULT_DURATION; $duration = DataBase::DEFAULT_DURATION;

4
db.php
View file

@ -198,10 +198,10 @@ class DataBase
} }
if (!isset($duration)) { if (!isset($duration)) {
$duration = self::DEFAULT_DURATION; $duration = self::DEFAULT_DURATION;
} elseif (!in_array($duration, self::OPTIONS_DURATION)) { } elseif (!key_exists($duration, self::OPTIONS_DURATION)) {
$duration = self::DEFAULT_DURATION; $duration = self::DEFAULT_DURATION;
} }
$duration = date('Y-m-d H:i:s', strtotime($duration)); $duration = date('Y-m-d H:i:s', strtotime(self::OPTIONS_DURATION[$duration]));
$stmt = $this->db->prepare(" $stmt = $this->db->prepare("
INSERT INTO clouds(code, text, size, delete_t) INSERT INTO clouds(code, text, size, delete_t)
VALUES (:code, :text, :size, :duration); VALUES (:code, :text, :size, :duration);