关于 php:SQLSTATE[42S22]: Column not found: 1054 Unknown column \\’$Values\\’ in \\’field list\\’\\’

SQLSTATE[42S22]: Column not found: 1054 Unknown column '$Valuess' in 'field list''

错误是 SQLSTATE[42S22]: Column not found: 1054 Unknown column '$Values' in 'field list'' in try2.php:31。我如何正确输入插入语句


只需使用"

中的字符串

1
$dbh->prepare("INSERT INTO register ($Keys) VALUES ($Valuess)")

因为在 '' 变量内部的行为类似于字符串,但在" 变量内部获取值。

也改变

1
 $Valuess ="'".implode("','", $Valuess)."'" ;

值必须用逗号分隔,例如 'gaurav','sundaram'


改用 bindParam - PHP 文档中的一个示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
$stmt = $dbh->prepare("INSERT INTO REGISTRY (name, value) VALUES (:name, :value)");
$stmt->bindParam(':name', $name);
$stmt->bindParam(':value', $value);

// insert one row
$name = 'one';
$value = 1;
$stmt->execute();

// insert another row with different values
$name = 'two';
$value = 2;
$stmt->execute();
?>