【发布时间】:2015-10-22 22:54:43
【问题描述】:
我在将数据从 php 插入数据库时遇到问题。
文件是:Patient.php
表名是:patient_tbl
表格里面是:头像和education
这里是插入代码:下面这段代码没有问题,'education'的值会被插入到表中
$sql = "INSERT INTO " . $this->_table;
$sql .= "education,";
$params = array(
urlencode($patient->getEducation()),
);
return $this->exec($sql, $params);
}
但现在这是我的问题,“头像”不要插入到表格中
错误消息是:“无法准备查询。”
$sql = "INSERT INTO " . $this->_table;
$sql .= "education, avatar, ";
$params = array(
urlencode($patient->getEducation()),
urlencode($patient->getAvatar()),
);
return $this->exec($sql, $params);
}
我的问题是什么?我找不到解决办法。
非常感谢您的帮助。
谢谢
【问题讨论】:
-
好吧,对于初学者来说,第二个查询中的尾随
,会导致语法错误。 -
打印出
$sql并将其包含在问题中。我的猜测是答案会很明显(比如列名周围没有括号)。 -
好吧,这是错误消息:无法准备查询。
-
你为什么使用 urlencode?span>
-
您应该接受(一个)答案,而不是在标题中添加“[SOLVED]”。
标签: php mysql sql-insert