dq8081 2013-08-09 17:06
浏览 17
已采纳

一个mysql连接中的多个查询无法使用php运行

Here is a part of my php code:

 foreach ($value->ahkam as $k => $v){
        echo $v->id."
";
        //Save into db one hokm
        $addHokm = "INSERT INTO qm_hokm (hokm_id, type, tooltip, line, x1, y1, x2, y2, radius, XOrigin, YOrigin, page_id)
            VALUES ($v->id,$v->type,'tooltip',0,$v->x1,$v->y1,$v->x2,$v->y2,$v->r,$v->XOrigin,$v->YOrigin,$pageNumber)";
        if(!mysqli_query($con, $addHokm))
            echo "Failed to insert into db...".$v->id."
";
    }

In fact, I am fetching a json structure sent by an ajax request from a client. I have many values in $value->ahkam but the problem is that only the first query is run and the others give me the error msg. Any help plz

UPDATE:

the result of echo is:

0
1
Failed to insert into db...1
2
Failed to insert into db...2

As you see, the hokm number 0 is added but not the others, I need to mention also that $pageNumer is a foeign key

  • 写回答

2条回答 默认 最新

  • drl959975 2013-08-09 17:24
    关注

    The problem is in your foreign key, it must not be unique. Like that, you can add multiple entries for one page_id. I hope it is the correct answer:)

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

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据