Php pdo在我的数据库中插入1列给出了错误

问题描述 投票:0回答:1

我不知道为什么这段代码不起作用,但是当我运行我的代码时,它会立即进入捕获。我一直在研究并尝试多种方法将其插入我的数据库,但为什么我不能插入它?是因为我只插入1个值吗?我的数据库表如下所示:

enter image description here

这是我的代码:

<?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;
?>
php sql
1个回答
0
投票

解决问题的两个步骤:

改变echo $stmt . "<br>" . $e->getMessage();to echo $e->getMessage();

使用VALUES而不是VALUE,使其显示为:

$stmt = $conn->prepare("INSERT INTO IA_Locatie (Ruimte_naam) VALUES (?)");
© www.soinside.com 2019 - 2024. All rights reserved.