Fix database date: 0000-00-00 -> NULL

This commit is contained in:
Chocobozzz
2017-02-05 17:07:56 +01:00
parent 1aac22b46d
commit ab7f85b404
14 changed files with 125 additions and 28 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
<?php
require(dirname(__FILE__) . "/config.php");
require(dirname(__FILE__) . "/config.php");
$options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$bdd = new PDO("mysql:host=$host;port=$port;dbname=$db", $user, $pass, $options);
+16
View File
@@ -1,5 +1,21 @@
<?php
function getMigrationSchemas() {
return [ 0, 5 ];
}
function updateSchema($bdd, $newKey) {
if ($newKey === 0) {
$req_string = 'INSERT INTO `application` (sql_schema) VALUES (?)';
}
else {
$req_string = 'UPDATE `application` SET `sql_schema` = ?';
}
$req = $bdd->prepare($req_string);
$req->execute(array($newKey));
}
function printError($str) {
echo '<div class="alert alert-danger" role="alert">' . $str . '</div>';
}
+5 -2
View File
@@ -119,8 +119,8 @@
$phone = "";
$online = 0;
$enable = 1;
$start = "0000-00-00";
$end = "0000-00-00";
$start = NULL;
$end = NULL;
$req = $bdd->prepare('INSERT INTO user (user_id, user_pass, user_mail, user_phone, user_online, user_enable, user_start_date, user_end_date)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)');
@@ -154,6 +154,9 @@
if ($field === 'user_pass') {
$value = hashPass($value);
}
else if (($field === 'user_start_date' || $field === 'user_end_date') && $value === '') {
$value = NULL;
}
// /!\ SQL injection: field was checked with in_array function
$req_string = 'UPDATE user SET ' . $field . ' = ? WHERE user_id = ?';
+3 -3
View File
@@ -1,12 +1,12 @@
<div class="col-md-6 col-md-offset-3">
<nav class="navbar navbar-default">
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li <?php if(!isset($_GET['admin'])) echo 'class="active"'; ?>><a href="index.php">Configurations</a></li>
<li <?php if(isset($_GET['admin'])) echo 'class="active"'; ?>><a href="index.php?admin">Administrator</a></li>
</ul>
</div>
</nav>
</div>
</div>