dongza3124 2015-05-08 20:04
浏览 23
已采纳

插入表时出现MySQL语法错误[关闭]

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.

$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.

The results are posted to invoiceadd.php which contains this code.

$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"

  • 写回答

2条回答 默认 最新

  • doukang8949 2015-05-08 20:08
    关注

    you're missing a comma, right there ...

    enter image description here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用