dtzh131555 2016-12-04 17:48
浏览 26

循环中的SQL注入不起作用

        <?php
include '../connectdb.php';


$sqlNAME = 'INSERT INTO group_general (group_name)
VALUES (?)';

if($statementNAME = $connect->prepare($sqlNAME)) {

    $statementNAME->bind_param(

        "s",
        $_POST['groupName']
        );

    $statementNAME->execute();
}

$groupName = $_POST['groupName'];

$selectGROUPID = 'SELECT * FROM group_general WHERE group_name = "'.$groupName.'"';

$resultGROUPID = $connect->query($selectGROUPID);

if ($resultGROUPID->num_rows > 0) {
    $rowGROUPID = $resultGROUPID->fetch_assoc();
}

/* The error is somewhere around here~ish */

for ($x=0; $x<sizeof($_POST['addedUsers']); $x++) { 
    $rowUSERS[$x] = $_POST['addedUsers'][$x];

    $sqlUSERS = 'INSERT INTO group_users (user_name, group_id)
    VALUES ("'.$rowUSERS[$x].'", "'.$rowGROUPID['group_id'].'")';

    if($statementUSERS = $connect->prepare($sqlUSERS)) {


    if ($statementUSERS->execute()) {

        echo "Successfully created the group!";

    }
     else {
    echo "Failed to create the group...";
}
}
}
?>

So my issue is whenever a user selects multiple people (so the array $rowUSERS[] becomes more than only the 0 value), it only inserts the first selected user into the DB while it actually should loop through every selected user and insert it one by one. I really don't know what I did wrong here. Can you please look at it and help me?

  • 写回答

1条回答 默认 最新

  • dongzhi6927 2016-12-04 18:39
    关注

    Edit:

    I fixed it, for some reason my group_id row in the DB had a primary key.

    Sorry for bothering you guys,

    ~Lars

    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line