如何将状态更新到数据库? [英] How do I update status into database?

查看:81
本文介绍了如何将状态更新到数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是php的新手。我想为导师创建一个考勤页面。



 <  表格   名称  = 表单   方法  = 发布    actionadmin_attendance_edit.php  >  

< 表格 >
< thead >
< tr >
< th > 否。 < / th >
< th > 名称 < / th >
< th > 状态 < < span class =code-leadattribute> / th >
< / tr >
< < /跨度> <温泉n class =code-leadattribute> / thead >
< tbody >

<? php

$ count = 1;
$ sel_query = 从出勤中选择* ORDER BY attendance_id desc;;
$ result = mysqli_query($ db,$ sel_query) trigger_error( 错误
mysqli_error($ db));


while($ row = mysqli_fetch_assoc($ result)){?>
< tr >
< td align = center > <? php echo $ count < /跨度>; ?> < / td < span class =code-keyword>>
< td align = center > <? php echo $ row [ student_name]; ?> < / td < span class =code-keyword>>
< td align = 中心 >

< 输入 type = hidden 名称 = user_id [] = <? php echo $ row [ user_id];? >
/>
< 输入 < span class =code-attribute> type = hidden 名称 = name [] value = <?php echo $ row [ student_name];

> />
< 输入 < span class =code-attribute> name = attendance [] type = radio value = present / > 目前
< 输入 名称 = 出勤[] < span class =code-attribute> type = radio value = 已故 / > Late
< input name = 出勤[] type = radio = 缺席 / > 缺席< / td >

< / tr >

<? php $ count ++; } ?>
< / tbody >
< / table >

< p > < input name = 提交 type = 提交 value = 更新 / > < / p >

< / form >





 <?php  


if(isset($ _ POST [' submit']) )
{

foreach ($ attendance as $ name = > $ attendance_status)
{

$ trn_date = date(' Ym-d');
$ user_id = $ _POST [' user_id ] [$名称];
$ student_name = $ _POST [' name ] [$名称];

$ update = 更新考勤设置user_id ='。$ user_id 。 ',student_name ='。$ student_name。 ',
attendance_status ='
。$ attendance_status。 ',date ='。$ trn_date。 '

;
mysqli_query($ db,$ update) trigger_error( 错误! .mysqli_error($ db));
header(' location:admin_attendance.php');

}





我的尝试:



我的代码可以告诉我任何错误。谢谢。

解决方案

< blockquote> count = 1;


sel_query = 从出勤中选择* ORDER BY attendance_id desc;;


result = mysqli_query(


i'm new to php. i want to create a attendance page for tutor.

<form name="form" method="post" action"admin_attendance_edit.php> 

    <table>
    <thead>
    <tr>
    <th>No.</th>
    <th>Name</th>
    <th>Status</th>
    </tr>
    </thead>
    <tbody>
					
    <?php
					
    $count=1;
	$sel_query="Select * from attendance ORDER BY attendance_id desc;";
	$result = mysqli_query($db,$sel_query) or trigger_error("Error". 
    mysqli_error($db));
															
					
	while($row = mysqli_fetch_assoc($result)) {?>
	<tr>
    <td align="center"><?php echo $count; ?></td>
	<td align="center"><?php echo $row["student_name"]; ?></td>
	<td align="center">

    <input type="hidden" name="user_id[]" value="<?php echo $row["user_id"];?>" 
    />
    <input type="hidden" name="name[]" value="<?php echo $row["student_name"]; ? 

    >" />
	<input  name="attendance[]" type="radio" value="present" />Present
	<input  name="attendance[]" type="radio" value="late"/>Late
	<input  name="attendance[]" type="radio" value="absent"/>Absent</td>									
						
	</tr>												
						
    <?php $count++; } ?>
    </tbody>
    </table>
       			
    <p><input name="submit" type="submit" value="Update" /></p> 
		
    </form>  



<?php
	
	
	if(isset($_POST['submit']))
	{	
			
    foreach ($attendance as $name=> $attendance_status)
		{
		
		$trn_date = date('Y-m-d');	
		$user_id = $_POST['user_id'][$name];
		$student_name =	$_POST['name'][$name];
		
		$update="update attendance set user_id='".$user_id."', student_name='".$student_name."' , 
										attendance_status='".$attendance_status."', date='".$trn_date."' 
										
										";
	mysqli_query($db, $update) or trigger_error( "Error!". mysqli_error($db));
	header('location: admin_attendance.php');
	
	}



What I have tried:

Can anyone tell me anything wrong in my code.thanks.

解决方案

count=1;


sel_query="Select * from attendance ORDER BY attendance_id desc;";


result = mysqli_query(


这篇关于如何将状态更新到数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆