duangai1916 2013-12-15 23:05
浏览 27
已采纳

将数据发布到mysql DB

I'am trying to send data from android as JSON to PHP in order to parse it and save in MySQL DB

this is the part of the PHP CODE

$JsonString = $_POST["DATA"];
$JsonData = json_decode($JsonString, TRUE);

$Add_First_Only = 0;
foreach ($JsonData['items'] as $item)
{
    $Order_ID = $item['Order_ID'];
    $Order_Row_Number = $item['Order_Row_Number'];
    $Order_Item_ID = $item['Order_Item_ID'];
    $Order_Course_ID = $item['Order_Course_ID'];
    $Order_Seat_No = $item['Order_Seat_No'];
    $Order_Row_Value_wo_Options = $item['Order_Row_Value_wo_Options'];
    $Order_Row_Value_with_options = $item['Order_Row_Value_with_options'];

if ($Add_First_Only == 0)
{
    $result = mysqli_query($con,
    "INSERT INTO order_items (Order_ID,Order_Row_Number,Order_Item_ID,Order_Course_ID,Order_Seat_No,Order_Row_Value_wo_Options, Order_Row_Value_with_options) 
    VALUES 
    (['$Order_ID'],['$Order_Row_Number'],['$Order_Item_ID'],['$Order_Course_ID'],
        ['$Order_Seat_No'],['$Order_Row_Value_wo_Options'],['$Order_Row_Value_with_options'])"
    );
    $Add_First_Only = 1;
}
}

and this is the error I get on the Eclipse LogCAT

12-16 02:00:01.800: V/TAG(1841): Error: 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 '['26'],['1'],['1'],['1'],['1'],['0'],['1'])' at line 4

As you can see from the error it self that I have values for the variables so non of them is a null value

The Question is what should I change or add to my sql syntax to fix this error ?

  • 写回答

3条回答 默认 最新

  • dsjklb0205 2013-12-15 23:16
    关注

    Remove the brackets around ['$Order_ID'] and the others

    Use '$Order_ID' instead of ['$Order_ID'] etc. for your VALUES

    if ($Add_First_Only == 0)
    {
        $result = mysqli_query($con,
        "INSERT INTO order_items (Order_ID,Order_Row_Number,Order_Item_ID,Order_Course_ID,Order_Seat_No,Order_Row_Value_wo_Options, Order_Row_Value_with_options) 
        VALUES 
        ('$Order_ID','$Order_Row_Number','$Order_Item_ID','$Order_Course_ID',
            '$Order_Seat_No','$Order_Row_Value_wo_Options','$Order_Row_Value_with_options')"
        );
        $Add_First_Only = 1;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?