while循环更新查询不起作用

时间:2015-05-23 12:23:38

标签: mysql

当我尝试更新记录时,我的更新查询是这样的,它只是更新第一条记录,之后它会给我所有其他记录

#1062 - 关键'processBackupIndex'重复输入'8-2015-05-16-13-2015-05-23-0.001-0.000-1-R-RI'

   for($k=0; $k<count($_REQUEST['designMasterId']); $k++)
    {
      $designMasterId    = isset($_REQUEST['designMasterId'][$k]) && $_REQUEST['designMasterId'][$k] != '' ? $_REQUEST['designMasterId'][$k] : 0;
      $reciveWet         = isset($_REQUEST['reciveWet'][$k]) && $_REQUEST['reciveWet'][$k] != '' ? $_REQUEST['reciveWet'][$k] : 0;
      $rejWet            = isset($_REQUEST['rejWet'][$k]) && $_REQUEST['rejWet'][$k] != '' ? $_REQUEST['rejWet'][$k] : 0;
      $desWet            = isset($_REQUEST['desWet'][$k]) && $_REQUEST['desWet'][$k] != '' ? $_REQUEST['desWet'][$k] : 0;

         $updateProBck = "UPDATE processbackup 
                        SET rDate           = '".$recDate."',
                            reciveWet       = '".$reciveWet."',
                            nextProcessId   = ".$nextProcessId.",
                            processMasterId = ".$processMasterId.",
                            rejWet          = ".$preRej."+".$rejWet.",
                            status = 'R',
                            nxtstatus = 'RI'
                        WHERE designMasterId = ".$designMasterId."
                               AND nextProcessId = ".$nextProcessId."
                               AND desWet = ".$desWet;
                  $updateProBckRes = mysql_query($updateProBck);
                  if(!$updateProBckRes)
                  {
                    echo "Recive Process Backup Insert Fail";
                  }
                  else
                  {
                    header("Location:processRecive.php");
                  }
}

1 个答案:

答案 0 :(得分:0)

您必须更换

header("Location:processRecive.php");

到循环文件的末尾。

因为现在如果第一次更新成功,则取消执行并将用户重定向到其他页面。

你的代码可能是:

    if(!$updateProBckRes)
    {
        echo "($k) Recive Process Backup Insert Fail";
        exit;
    }

}
header("Location:processRecive.php");