Php 不太清楚为什么这个准备好的声明是';行不通
出于某种原因,这只是没有插入到我的数据库 HTMLPhp 不太清楚为什么这个准备好的声明是';行不通,php,mysql,pdo,prepared-statement,Php,Mysql,Pdo,Prepared Statement,出于某种原因,这只是没有插入到我的数据库 HTML <form name="testimonials_form" method="post" action="insert/"> Name <input type="text" name="from" maxlegnth="100" /> Location <input type="text" name="where" maxlegnth="100" /> Text Snippet <
<form name="testimonials_form" method="post" action="insert/">
Name
<input type="text" name="from" maxlegnth="100" />
Location
<input type="text" name="where" maxlegnth="100" />
Text Snippet
<input type="text" name="text" maxlegnth="255">
<input type="submit" name="submit" value="Continue" />
</form>
名称
位置
文本片段
PHP
<?php
$from = $_POST['from'];
$where = $_POST['where'];
$text = $_POST['text'];
if (!$from || !$where || !$text) {
$error = "You have missed some fields.";
$solution = "Please go back and <a href=\"javascript:history.go(-1)\" target=\"_self\">try again</a>.";
} else {
$data_array = array(':from' => $from, ':where' => $where, ':text' => $text);
$insert_testimonial = $connect->prepare("
INSERT INTO `testimonials` (
text, from, where
) VALUES (
:text, :from, :where
)
");
$insert_testimonial->execute($data_array);
$amount = $insert_testimonial->rowCount();
if ($amount < 1) {
$error = "Something went wrong.";
$solution = "Please go back and <a href=\"javascript:history.go(-1)\" target=\"_self\">try again</a>.";
} else {
header ("Location: ../");
}
}
?>
我一直得到的是我的自定义错误“出错了”。因此没有500个错误(内部服务器错误),如果我回显$from、$where和$text,它会显示我在表单中键入的内容,我已经写了大约5次,以防我写错或什么的,但仍然没有运气。我知道不会有符号丢失或在错误的位置,因为它会返回500错误
有人知道这是怎么回事吗?像这样的代码我已经写了无数次了,但这似乎不起作用,所以我肯定错过了一些东西
from, where
在您的查询中需要
`from`, `where`
asfrom
和中的是MySQL中的保留字:
顺便说一句,这些是反勾号。依我看,你最好不要用这些词作为列名,但如果你这样做了,你通常需要使用反勾号。你有没有检查errorCode
?你用过吗?此外,正如@Shiplu所述,您应该检查错误代码或。也尝试了bindParam
,尝试了命名占位符和标记占位符,但仍然没有结果。至于我得到的错误信息:Array([0]=>42000[1]=>1064[2]=>您的SQL语法有错误;请查看与您的MySQL服务器版本对应的手册,以了解使用“from,where,text)值附近的正确语法…
这是与此代码相关的:print\r($insert\u testional->errorInfo())
我认为from
和where
必须是`from`
和`where`
,因为from
和where
是一个。顺便说一句,这些都是反勾号。在我看来,你最好不要用这些词作为列名。@JaredFarrish这可能是一个可能的答案