我不知道为什么这段代码不起作用,但是当我运行我的代码时,它会立即进入捕获。我一直在研究并尝试多种方法将其插入我的数据库,但为什么我不能插入它?是因为我只插入1个值吗?我的数据库表如下所示:
这是我的代码:
<?php
include "../includes/connection.php";
$ruimte_naam = $_POST['ruimte_naam'];
try{
$stmt = $conn->prepare("INSERT INTO IA_Locatie (Ruimte_naam) VALUE (?)");
$stmt->execute([$ruimte_naam]);
}catch(PDOException $e){
echo $stmt . "<br>" . $e->getMessage();
}
$conn = null;
?>
解决问题的两个步骤:
改变echo $stmt . "<br>" . $e->getMessage();
to echo $e->getMessage();
使用VALUES
而不是VALUE
,使其显示为:
$stmt = $conn->prepare("INSERT INTO IA_Locatie (Ruimte_naam) VALUES (?)");