I am trying to make a simple invoicing program. I have 1 form page where I can input customers and it saves that data to the table "customers" I then have a page where I can input invoice details. It pulls the customer information from the "customers" table and then saves that information along with the added information such as "cost" to the "invoice" table. It works, but as soon as I input any new information such as "cost" I get a syntax error.
我正在尝试制作一个简单的发票计划。我有一个表单页面,我可以输入客户,它将数据保存到表“客户”然后我有一个页面,我可以输入发票详细信息。它从“客户”表中提取客户信息,然后将该信息与“成本”等附加信息一起保存到“发票”表中。它有效,但只要我输入任何新信息,如“费用”,我就会收到语法错误。
This is the code that pulls the info from the "customers" table.
这是从“customers”表中提取信息的代码。
$gresult = ''; //declare global variable
if(isset($_POST["action"]) and $_POST["action"]=="edit"){
$id = (isset($_POST["ci"])? $_POST["ci"] : '');
$sql = "select contact_id, first_name, last_name,
contact_no, address,
company, email, cost from customers
where contact_id = $id";
$result = mysqli_query($link, $sql);
if(!$result)
{
echo mysqli_error($link);
exit();
}
$gresult = mysqli_fetch_array($result);
include 'invoiceupdate.php';
exit();
Which is then passed to invoiceupdate.php which is just a simple web form.
然后将其传递给invoiceupdate.php,这只是一个简单的Web表单。
The results are posted to invoiceadd.php which contains this code.
结果发布到invoiceadd.php,其中包含此代码。
$sql = "insert into invoice set
first_name = '$fname',
last_name = '$lname',
contact_no = '$contact_no',
address = '$ResAddress',
company = '$Company',
email = '$CompAddress'
cost = '$cost'";
Everything works fine if I take out cost = '$cost' but if its in there I get "Error Saving Data. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'cost = '5'' at line 9"
如果我拿出cost ='$ cost',一切正常,但如果它在那里我得到“错误保存数据。你的SQL语法有错误;检查与你的MySQL服务器版本对应的手册,以便使用正确的语法在第9行'cost ='5''附近
2 个解决方案
#1
you're missing a comma, right there ...
你错过了一个逗号,就在那里......
#2
you are missing a comma after email = '$CompAddress'
你错过了电子邮件='$ CompAddress'之后的逗号
#1
you're missing a comma, right there ...
你错过了一个逗号,就在那里......
#2
you are missing a comma after email = '$CompAddress'
你错过了电子邮件='$ CompAddress'之后的逗号