From 1e8e8396130ed97515d77f3f168d6c4628f70b38 Mon Sep 17 00:00:00 2001 From: zPlus <-> Date: Mon, 6 Jun 2016 00:14:51 +0200 Subject: [PATCH] Fix "duplicate key error" when changing to email='' --- database.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/database.php b/database.php index 79619677..1ac173dc 100644 --- a/database.php +++ b/database.php @@ -824,10 +824,18 @@ class Database { $query = $this->database->prepare ( 'UPDATE `user`' . - 'SET `about` = ?, `email` = ? ' . - 'WHERE `id` = ?'); - - $query->execute (array ($about, $email, $user_id)); + 'SET `about` = :about, `email` = :email ' . + 'WHERE `id` = :user_id'); + + $query->bindValue (':about', $about, PDO::PARAM_STR); + $query->bindValue (':user_id', $user_id, PDO::PARAM_INT); + + if (NULL == $email || '' == $email) + $query->bindValue (':email', NULL, PDO::PARAM_NULL); + else + $query->bindValue (':email', $email, PDO::PARAM_STR); + + $query->execute (); } /**