【发布时间】:2015-08-14 17:22:49
【问题描述】:
我正在尝试在我的网站上实现用户阻止功能,但查询更新出现问题,我看不出主要原因是什么。错误报告为 ON (E_ALL),其他一切正常(注册、登录、查找用户、名称更新),但组更新除外。
if (Input::exists()) {
if (isset($_POST['block-username'])) {
$banUser = Input::get('ban');
if(!empty($banUser)) {
if ($user->find($banUser) == false) {
echo "That user doesn't exists.";
} else {
try {
$user->update(array('group' => 4));
echo 'User {$user->data()->username} is blocked.';
} catch (Exception $e) {
die($e->getMessage());
}
}
}
}
}
这里是更新函数:
/**
* Update in database
*
* @param string $table
* @param int $id
* @param array $fields
* @return bool
*/
public function update($table, $id, array $fields) {
$set = '';
$x = 1;
$countFields = count($fields);
foreach ($fields as $name => $value) {
$set .= "{$name} = ?";
if ($x < $countFields) {
$set .= ',';
}
$x++;
}
$sql = "UPDATE {$table} SET {$set} WHERE ID = {$id}";
if (!$this->query($sql, $fields)->error()) {
return true;
}
return false;
}
但是,更新使用名称:
try {
$user->update(array('name' => Input::get('name')));
Session::flash('home', 'Your details have been updated.');
Redirect::to('index.php');
} catch(Exception $e) {
die($e->getMessage());
}
我已经检查了与数据库的连接、包含的文件和 MySQL 权限。我刚刚收到消息There was a problem updating。
更新:这是我在die($e->getMessage()); 之前使用print_r($e); 得到的:
Exception Object ( [message:protected] => There was a problem updating
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => /home/nikola/public_html/matehub/classes/User.php
[line:protected] => 52
[trace:Exception:private] => Array (
[0] => Array (
[file] => /home/nikola/public_html/matehub/admin.php
[line] => 113
[function] => update
[class] => User
[type] => ->
[args] => Array ( [0] => Array ( [group] => 4 )
)
)
)
[previous:Exception:private] => )
【问题讨论】:
标签: php