使用php更新数据库中的值

时间:2017-10-30 09:13:56

标签: php

当我更新其中一个用户时,它也会更新一些用户的时间。 它正在更新,但我不知道为什么其他用户也是如此。 如果我编辑超时,它将改变某些用户的超时。抱歉我的英语不好。

logs.php

<tbody>
<?php 
$user_query=mysqli_query($dbcon,"SELECT * FROM user_logs_tbl where create_date >= date(now())")or die(mysqli_error($dbcon));
//$user_query=mysqli_query($dbcon,"SELECT * FROM user_logs_tbl")or die(mysqli_error($dbcon));

while($row=mysqli_fetch_array($user_query)){
    $ids = isset($_row['id']) ? $_row['id'] : '';   
    $_SESSION=$id=$row['user_id']; 
    $user_query2=mysqli_query($dbcon,"SELECT * FROM users_tbl where id='$id'")or die(mysqli_error($dbcon)); 
    $row2= mysqli_fetch_array($user_query2);?>
    <tr class="del<?php echo $ids ?>">
        <td>
            <?php echo $row['id']; ?>
        </td>                              
        <td>
            <?php echo $row2['firstname']." ".$row2['middlename']." ".$row2['lastname']; ?>     
        </td>
        <td>
            <?php $course= $row['create_date']; 
                if($course == '') {
                    echo "N/A";                 
                } else {
                    echo $course;
                }   
            ?>
        </td> 
        <td>
            <?php echo $tayming=$row['time_in']; ?>
        </td> 
        <td>
            <?php $yr_lvl=$row['time_out'];
                if($yr_lvl == '') {             
            ?>  
             <a rel="tooltip"  title="Timeout" id="<?php echo $id; ?>" href="#timeout<?php echo $id; ?>" data-toggle="modal" class="btn btn-info"><i class="icon-minus icon-large"></i>&nbsp;Manual Time-Out</a>
            <?php include('modal_time_user.php');
                } else {
                   echo $yr_lvl;
                }    
            ?>
        </td>         
        <td>
            <?php   
                $d=mktime(9, 06);
                $nice=date("h:i", $d);
                if($tayming >= $nice) {
                    echo "You're Late! Bro!";
                } else {
                    echo "Very Good!";
                    }   
            ?>
        </td>
        <td>
            <a rel="tooltip"  title="Edit" id="<?php echo $id; ?>" href="#edit<?php echo $id; ?>" data-toggle="modal" class="btn btn-success"><i class="icon-pencil icon-large"></i>&nbsp;Edit</a>
            <?php include('modal_edit_time.php'); ?>
        </td>  
        <?php include('toolttip_edit_delete.php'); ?>
    </tr>
<?php  } ?>
</tbody>

这是模式,如果单击按钮编辑 的 modal_edit_time.php

<div id="edit<?php echo $id; ?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-body">
        <div class="alert alert-info"><strong>Manual Time-In</strong></div>
<form class="form-horizontal" method="post">
        <div class="control-group">

            <label class="control-label" style="margin-left:29%;" for="inputEmail">Employee:</label>
            <div class="controls">
        <?php   $wiw=mysqli_query($dbcon,"SELECT * FROM users_tbl where id='$id'");
                $row2= mysqli_fetch_array($wiw);?>

            <input type="hidden" id="inputEmail" name="id" value="<?php echo $row['user_id']; ?>" required>
            <input type="text" name="userid" value="<?php echo $row2['firstname']." ".$row2['middlename']." ". $row2['lastname'];?>" readonly>  
</div>
    </div>

    <div class="control-group">
            <label class="control-label" style="margin-left:29%;" for="inputEmail">Date:</label>        
            <div class="controls">
            <input type="date" id="inputEmail" value="<?php echo $row['create_date'];?>" name="create_date" placeholder="Date" required>
            </div>
        </div>


            <div class="control-group">
            <label class="control-label" style="margin-left:29%;" for="inputEmail">Time-In:</label>     
            <div class="controls">
            <input type="time" id="inputEmail" value="<?php echo $row['time_in'];?>" name="timein" placeholder="Time" required>
            </div>
        </div>

        <div class="control-group">
            <label class="control-label" style="margin-left:29%;" for="inputEmail">Time-Out:</label>        
            <div class="controls">
            <input type="time" id="inputEmail"  value="<?php echo $row['time_out'];?>" name="timeout" placeholder="Time" required>
            </div>
        </div>

        <div class="control-group">
            <div class="controls">
            <button name="edit" type="submit" class="btn btn-success"><i class="icon-save icon-large"></i>&nbsp;Save</button>
            </div>
        </div>
</form>
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true"><i class="icon-remove icon-large"></i>&nbsp;Close</button>
    </div>
</div>

<?php echo $id;
if (isset($_POST['edit'])){
$userid=$_POST['id'];
$timein=$_POST['timein'];
$timeout=$_POST['timeout'];
$create_date=$_POST['create_date'];
mysqli_query($dbcon,"UPDATE user_logs_tbl set time_in='$timein',time_out = '$timeout',create_date ='$create_date' where id='$id'")or die(mysqli_error($dbcon));
$yourURL="logs.php";
echo ("<script>location.href='$yourURL'</script>");


}
?>

网络界面:

enter image description here

数据库:

enter image description here

0 个答案:

没有答案