0

当我尝试将记录插入数据库时​​,我的 php 代码出现了一个奇怪的问题。

$db=sqlite_open("Architect.db");

$CustomerNo = sqlite_query($db, "SELECT MAX(CustomerNo) FROM Customer");
$row=sqlite_fetch_array($CustomerNo);
$CustomerNumber= "$row[0]";

echo "CustomerNo: " . $CustomerNumber . "<br>";

$CustomerNumberup= ($CustomerNumber + 1);

echo "CustomerNo: " . $CustomerNumberup . "<br>";

//This is the function that actually adds things to the database.
function Store($Name,$Company,$PhoneNo,$Address1,$Address2,$County,$PostCode,$CustomerNumberup){

}
//this calls the function and passes it the variables
Store($Name,$Company,$PhoneNo,$Address1,$Address2,$County,$PostCode,$CustomerNumberup)

基本上我得到了最高的客户编号,将其加 1,然后将其用作新条目的客户编号。

在输出页面上,我要求它分几个阶段输出客户编号。它显示 CustomerNumber 为 1 它显示 CustomerNumberUp 为 2 然后它给了我确切的错误

Warning: sqlite_query() expects parameter 1 to be resource, string given in I:\wwwroot\Year 3\Project Stuff\IP40 Website\addCustomer.php on line 52

其中第 52 行是插入查询。我已经尝试了各种方法来解决这个问题,欢迎提出任何建议。

4

2 回答 2

1

参数 1 看起来像我的名字。客户编号在最后。

顺便说一句,如果您的应用程序变得繁忙,您将使用您的方法获得重复的客户编号。sqllite 没有自动增量字段吗?

于 2013-03-20T01:42:14.557 回答
0

问题是您的数据库名称

$db=sqlite_open("Architect.db");

如果被删除,它是否按预期工作.db

于 2013-03-20T01:45:30.890 回答