php更新,更新一些值

时间:2016-11-01 11:44:46

标签: php mysql mysqli

我有大桌子,那里是夜间和白天的工作时间。 由于某种原因,某些值会像valuex2一样更新为什么?

我的代码:

    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);

    }

为了更新夜间,我有相同的代码但是 与夜变量 我看不出有什么不对吗?

我为长代码道歉!

1 个答案:

答案 0 :(得分:1)

运行此代码,您自己可能会发现错误

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);
}