Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql SQL-Loop+;表中的更新_Mysql_Sql - Fatal编程技术网

Mysql SQL-Loop+;表中的更新

Mysql SQL-Loop+;表中的更新,mysql,sql,Mysql,Sql,使用POST方法$tab_tuto_sauvegarde=$\u POST['tableau_valeurs_modifies']Ajax请求会向我返回以下信息: [Chapitres] => Array [0] => Array [titre_chapitre] => BONJOUR [id_chapitre] => 1 [2] =>

使用POST方法
$tab_tuto_sauvegarde=$\u POST['tableau_valeurs_modifies']Ajax请求会向我返回以下信息:

 [Chapitres] => Array
            [0] => Array
                    [titre_chapitre] => BONJOUR
                    [id_chapitre] => 1

            [2] => Array
                    [titre_chapitre] => Manger
                    [id_chapitre] => 3
我有一个名为
'Chapitres'

|  Id_chapitre  ||  titre_chapitre |
__________________________________
|    1          ||    C01          |
|    2          ||    C02          |
|    3          ||    C03          |
|    4          ||    C04          |
...
我需要更新我的表中的
'titre\u chapitre'
,其中id\u chapitre=“[id\u chapitre]return by ajax”
中的
'titre\u chapitre'
(在本例中,索引[0]和[2]…但它可以是索引[0]和[1]和[4]…)

结果一定是这样

|  Id_chapitre  ||  titre_chapitre |
__________________________________
|    1          ||    BONJOUR      |
|    2          ||    C02          |
|    3          ||    Manger       |
|    4          ||    C04          |
...
我试过了,但是

if (isset ($tab_tuto_sauvegarde['Chapitres'])){
    foreach($tab_tuto_sauvegarde['Chapitres'] as $index => $valeur){
    mysqli_query($BDD_connect, "UPDATE Chapitres SET titre = titre_chapitre(from array ajax) WHERE Id_chapitre = id_chapitre(from array ajax) "); 
    }
}

下面是如何使用预先准备好的语句来完成它

$stmt = mysqli_prepare($BDD_connect, "UPDATE Chapitres SET titre = ? WHERE id_tutoriel = ?");
mysqli_stmt_bind_param($stmt, "si", $titre, $id);
foreach ($tab_tuto_sauvegarde['Chapitres'] as $chapitre) {
    $titre = $chapitre['titre_chapitre'];
    $id = $chapitre['id_chapitre'];
    mysqli_execute($stmt);
}

请使用参数化查询。您应该检查
$tab_tuto_sauvegarde['Chapitres']
是否也是一个数组。在循环之前准备一个语句。然后使用
foreach(tab_tuto_sauvegarde['Chapitres']作为$row){//执行查询,并将当前行的值绑定到参数}
好的,我将尝试这个;)请原谅我,但我是PHP的大傻瓜。。。如何将第一行中的“?”替换为“$titre”和第二行“?”替换为“$id”?第二行的“si”是什么?