douhuike3199 2016-11-01 11:44
浏览 79
已采纳

php更新,更新一些值double

i have large table where is night and day work hour. for some reason some of the values are updated like valuex2 why?

my code:

    if ($source=='editEmployeeHours') {

    $object=htmlentities($_POST['object'], ENT_QUOTES, "UTF-8");
    $period=htmlentities($_POST['period'], ENT_QUOTES, "UTF-8");
    $m=htmlentities($_POST['m'], ENT_QUOTES, "UTF-8");  
    $y=htmlentities($_POST['y'], ENT_QUOTES, "UTF-8");
    $date=htmlentities($_POST['date'], ENT_QUOTES, "UTF-8");    
    $records=htmlentities($_POST['records'], ENT_QUOTES, "UTF-8");
    include('inc/s.php'); 
$g = null;      
while ($g <= $records){
$g++;
$edithoursday = $personday = $day = null;
    $edithoursday=htmlentities($_POST['edithoursday'][$g], ENT_QUOTES, "UTF-8");
    $personday=htmlentities($_POST['personday'][$g], ENT_QUOTES, "UTF-8");
    $day=htmlentities($_POST['day'][$g], ENT_QUOTES, "UTF-8");

    if($edithoursday!=''){
                $resultd = mysqli_query($conn,"SELECT * FROM timesheets WHERE day='".$day."' AND person_code = '".$personday."' AND object_id = '".$object."' AND period_code='".$period."' AND type='0'");
                if (!$resultd){die("Attention! Query to show fields failed.");}
    if (mysqli_num_rows($resultd)!=0){  
                $queryied = "UPDATE timesheets SET value='".$edithoursday."' WHERE day='".$day."' AND person_code = '".$personday."' AND object_id = '".$object."' AND period_code='".$period."' AND type='0'";
                mysqli_query($conn, $queryied); 
         }
    }
}

        header("Location: "home");
        die(0);

    }

For updating night hours i have same code but with nights variables Is there anything wrong that i do not see?

My apologize for long code!

  • 写回答

1条回答 默认 最新

  • doubaoguo7469 2016-11-01 12:33
    关注

    Run this code, probably you will find error yourself

    if ($source == 'editEmployeeHours')
    {
    
        $object  = htmlentities($_POST['object'], ENT_QUOTES, "UTF-8");
        $period  = htmlentities($_POST['period'], ENT_QUOTES, "UTF-8");
        $m       = htmlentities($_POST['m'], ENT_QUOTES, "UTF-8");
        $y       = htmlentities($_POST['y'], ENT_QUOTES, "UTF-8");
        $date    = htmlentities($_POST['date'], ENT_QUOTES, "UTF-8");
        $records = htmlentities($_POST['records'], ENT_QUOTES, "UTF-8");
        include('inc/s.php');
        $g       = null;
        echo "<pre>";
        while ($g <= $records)
        {
            echo "<br><br>---------------------------------------<br><br>";
            $g++;
            $edithoursday = $personday    = $day          = null;
            $edithoursday = htmlentities($_POST['edithoursday'][$g], ENT_QUOTES, "UTF-8");
            $personday    = htmlentities($_POST['personday'][$g], ENT_QUOTES, "UTF-8");
            $day          = htmlentities($_POST['day'][$g], ENT_QUOTES, "UTF-8");
    
            echo "<pre>";
            print_r(array('edithoursday' => $edithoursday, 'personday' => $personday, 'day' => $day));
            echo "</pre>";
            if ($edithoursday != '')
            {
                $q = "SELECT * FROM timesheets WHERE
                day='" . $day . "' AND
                person_code = '" . $personday . "' AND
                object_id = '" . $object . "' AND
                period_code='" . $period . "' AND
                type='0'";
    
                echo "<pre>";
                echo $q;
                echo "</pre>";
    
                $resultd = mysqli_query($conn, $q);
                if (!$resultd)
                {
                    die("Attention! Query to show fields failed.");
                }
                if (mysqli_num_rows($resultd) != 0)
                {
                    $queryied = "UPDATE timesheets SET "
                        . "value='" . $edithoursday . "' "
                        . "WHERE "
                        . "day='" . $day . "' AND "
                        . "person_code = '" . $personday . "' AND "
                        . "object_id = '" . $object . "' AND "
                        . "period_code='" . $period . "' AND "
                        . "type='0'";
                    echo "<pre>";
                    echo $queryied;
                    echo "</pre>";
                    mysqli_query($conn, $queryied);
                }
            }
        }
        echo "</pre>";
        header("Location: home");
        die(0);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页
  • ¥15 376.1电表主站通信协议下发指令全被否认问题
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥15 复杂网络,变滞后传递熵,FDA
  • ¥20 csv格式数据集预处理及模型选择
  • ¥15 部分网页页面无法显示!
  • ¥15 怎样解决power bi 中设置管理聚合,详细信息表和详细信息列显示灰色,而不能选择相应的内容呢?
  • ¥15 QTOF MSE数据分析
  • ¥15 平板录音机录音问题解决
  • ¥15 请问维特智能的安卓APP在手机上存储传感器数据后,如何找到它的存储路径?