我正在本地编写一个脚本,遇到了一些问题,让我感到困惑。我试图将一些数据插入表中,我只是没有让它插入。我已经转储了导致执行实际查询的所有变量,并且它们都是真实的和现有的但是一旦我转储执行它返回false。我在这里真的很难过。任何人都可以帮助我吗?
if (isset($_POST['submit'])) {
$errors = '';
$clan_name = $_POST['clan_name'];
$short_desc = $_POST['clan_short_desc'];
$database = Database::getDatabase();
$driver = $database->getDriver();
$stmt = $driver->prepare(
'INSERT INTO ' . TABLE_PREFIX . 'clans
VALUES (0, :id_user, :clan_name, :clan_short_desc, :clan_date, 0);'
);
$stmt->bindValue(':id_user', $user->getId(), PDO::PARAM_STR);
$stmt->bindValue(':clan_name', $clan_name, PDO::PARAM_STR);
$stmt->bindValue(':clan_short_desc', $short_desc, PDO::PARAM_STR);
$stmt->bindValue(':clan_date', time(), PDO::PARAM_INT);
$stmt->execute();
var_dump($stmt->bindValue(':id_user', $user->getId(), PDO::PARAM_STR));
var_dump($stmt->bindValue(':clan_name', $clan_name, PDO::PARAM_STR));
var_dump($stmt->bindValue(':clan_short_desc', $short_desc, PDO::PARAM_STR));
var_dump($stmt->bindValue(':clan_date', time(), PDO::PARAM_INT));
//header('Location: index.php?action=viewclans');
//die();
}
答案 0 :(得分:2)
尝试:
'INSERT INTO ' . TABLE_PREFIX . 'clans
(id_user,clan_name, clan_short_description, clan_date)
VALUES
( :id_user, :clan_name, :clan_short_desc, :clan_date);'
并在执行后立即添加:
$stmt->execute();
print_r ($stmt->errorInfo());