这是查询代码:PHP MySQL查询不工作
if (isset($_POST['moduleAction']) && ($_POST['moduleAction'] == 'edit')) {
$date = date('Y-m-d H:i:s', time());
$stmt = $db->prepare('UPDATE todolist SET what = ?, priority = ?, added_on = ? WHERE id = ?');
$stmt->execute(array($what, $priority + 1, $date, $id));
}
我的数据库连接:
<?php
try {
$db = new PDO('mysql:host=' . DB_HOST .';dbname=' . DB_NAME . ';charset=utf8mb4', DB_USER, DB_PASS);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
} catch (Exception $e) {
showDbError('connect', $e->getMessage());
}
在同一文件中的数据库不执行查询,另一页上我正在执行查询到相同的数据库没有问题。我试着在没有准备好的语句的情况下执行它,双引号,重新启动te连接,......没有任何作用。
任何人都可以把我推向正确的方向吗?
编辑
设置变量:
$priorities = array('low','normal','high'); // The possible priorities of a todo
$formErrors = array(); // The encountered form errors
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0; // The passed in id of the todo
$what = isset($_POST['what']) ? $_POST['what'] : ''; // The todo that was sent in via the form
$priority = isset($_POST['priority']) ? $_POST['priority'] : 'low'; // The priority that was sent in via the form
在你的提取中,你不会设置'$ what','$ priority'或'$ id'。这些变量在哪里设置? – bcmcfc 2014-10-19 17:10:19
我编辑了我的文章。 – user3165926 2014-10-19 17:13:16