【发布时间】:2013-04-10 03:01:58
【问题描述】:
使用 php 插入记录并访问数据库 - 获取“odbc_exec() 的参数计数错误”一切正常,但我无法将其插入数据库。
$R1=rand(1,20);
$db=odbc_connect('Eightball','','');
$sql = "SELECT * FROM theAnswers";
$sql .= " WHERE id = " . $R1;
$rs=odbc_exec($db,$sql);
while (odbc_fetch_row($rs))
{
$FinalAnswer=odbc_result($rs,"Answer");
$newdate = date('M j, Y');
$newQuestion = $_POST["Question"];
if(isset($_SERVER['HTTP_REFERER'])) {
$Thereferrer=$_SERVER['HTTP_REFERER'];
}
$theIPAddress=$_SERVER['REMOTE_ADDR'];
echo $theIPAddress;
echo $Thereferrer;
echo $newQuestion;
echo $FinalAnswer;
echo $newdate;
}
$sql = "INSERT INTO theQuestions (ipaddress, referrer, Question, Answer, theDate) VALUES ('$theIPAddress', '$Thereferrer', '$newQuestion', '$FinalAnswer', newdate)";
$rs=odbc_exec($db,$sql);
$result = odbc_exec($sql);
if (!$result) {exit('Execution failed!');}
【问题讨论】:
-
您不需要在 INSERT 语句中的 newdate 变量上加上 $ 吗?
-
我确信插入语句的日期字段有问题。在访问中,它被设置为日期/时间数据类型
-
试过 $newdate, '$newdate'
-
参见:delphi.about.com/od/delphitips2007/qt/datetime_sql.htm 这是 Delphi 的,但 PHP 也是如此
-
我删除了 ipaddress、referrer 和它们的值并运行了查询,但没有更新,因为数据类型设置为“允许零长度不”
标签: php ms-access sql-insert