0

我在将数据插入 Access 表(“测试”)时遇到问题。我有一个 html 表单,应该使用我的 PHP 来插入。一切似乎都正常(没有错误),但是当我查看我的 Access 表(“测试”)时,没有插入任何内容,我不知道为什么。SELECT 工作正常,由于某种原因我无法插入。

谢谢您的帮助。

测试.html:

<html>
<body>

Enter Customer Information
<br>
(* indicates required fields)

<p>
<form action="test.php" method="post">
Last Name*: <input type="text" name="last">
<br>
First Name*: <input type="text" name="first">
</td>
</tr>
<input type="submit">
</form>
</body>
</html>

测试.php:

<?php
$conn=odbc_connect('testdb','','');
$sql="INSERT INTO test (last, first)
VALUES
('$_POST[last]','$_POST[first]')" or die (sql_error);
odbc_exec($conn, $sql) or die (exec_error);
odbc_commit($conn) or die (comm_error);
odbc_close($conn);
echo "1 record added";
?> 
4

1 回答 1

1

问题解决了。添加 odbc_errormsg 行后,我得到:[Microsoft][ODBC Microsoft Access Driver] 操作必须使用可更新查询。

我的 ODBC 管理窗口没有标记“只读”。但是,我的访问数据库不允许普通用户写入或修改。在调整文件夹和 *mdb 文件的权限后,它起作用了。

感谢 Andrewsi 帮助我解决了这个问题。从现在开始,我将在每个命令之后添加 errormsg 行!

于 2013-08-29T22:56:29.353 回答