一个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

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:)

Based on your comments, it appears that your query is inserting a duplicate value for the page_id value, which appears to be set as a field that cannot have duplicate values. According to your query, you're using $pageNumber for that field, but I don't see it changing in your loop. You either need to get rid of the constraint preventing you from using the same value or make sure that $pageNumber has a value that isn't being used already.