Reputation: 115
Having a strange problem with my php code when i try and insert a record into my database.
$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)
Basically i am getting the highest customer number, adding 1 to it and then using it as the customer number for the new entry.
On the output page i have asked for it to output the customer number at several stages. It Shows CustomerNumber as 1 It Shows CustomerNumberUp as 2 it then gives me the exact error
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
Where linee 52 is the insert query. I have tried allsorts to fix this, any suggestions are welcome.
Upvotes: 0
Views: 331
Reputation: 231
The issue is your database name
$db=sqlite_open("Architect.db");
Does it work as intended if .db
is removed?
Upvotes: 0
Reputation: 20804
Parameter 1 looks like the name to me. Customer number comes at the end.
By the way, if your app ever gets busy, you will get duplicate customer numbers with your approach. Does sqllite not have autoincrement fields?
Upvotes: 1