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);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧