【发布时间】:2015-09-02 03:31:34
【问题描述】:
我想要完成的是
- 将数据从 MySQL 数据库获取到一个表中,该表仅包含用户忘记登录或注销的行(完成)
- 更改表中的数据(完成)
- 点击提交,将表中所有数据更新到MySQL数据库中
我已经让每个输入/值都有自己的名称/ID,例如。 (name0, name1, name2)
我只是不太确定如何将所有数据从表中获取到 MySQL 数据库
这是我当前的代码:
$query = "SELECT ID, name, date, start, end, location, leavetype, comments FROM test WHERE `start`='' AND `date`<>'$today_date' OR `end`='' AND `date`<>'$today_date'";
$result=mysql_query($query);
$num=mysql_numrows($result);
?>
<section>
<form>
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<th hidden>
<font face="Arial, Helvetica, sans-serif">Datename</font>
</th>
<th>
<font face="Arial, Helvetica, sans-serif">ID</font>
</th>
<th>
<font face="Arial, Helvetica, sans-serif">Name</font>
</th>
<th width="80px">
<font face="Arial, Helvetica, sans-serif">Date</font>
</th>
<th>
<font face="Arial, Helvetica, sans-serif">Start</font>
</th>
<th>
<font face="Arial, Helvetica, sans-serif">End</font>
</th>
<th style="width:120px;">
<font face="Arial, Helvetica, sans-serif">Location</font>
</th>
<th style="width:80px;">
<font face="Arial, Helvetica, sans-serif">Leave-Type</font>
</th>
<th>
<font face="Arial, Helvetica, sans-serif">Comments</font>
</th>
</tr>
<?php
$i=0;while ($i < $num) {$f1=mysql_result($result,$i,"ID");
$f2=mysql_result($result,$i,"name");
$f3=mysql_result($result,$i,"date");
$f4=mysql_result($result,$i,"start");
$f5=mysql_result($result,$i,"end");
$f6=mysql_result($result,$i,"location");
$f7=mysql_result($result,$i,"leavetype");
$f8=mysql_result($result,$i,"comments");
echo '
<tr>
<td hidden>
<font face="Arial, Helvetica, sans-serif">';echo "$f3$f2";echo '</font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif"> <input type="text" name="ID'; echo $i; echo '" style="width:35px;" Value="'; echo $f1;echo '" style="width:80px" disabled></font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif"> <input type="text" name="name'; echo $i; echo '" style="width:120px;" Value="'; echo $f2;echo '" style="width:80px" disabled></font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif"> <input type="text" name="date'; echo $i; echo '" pattern="[0-9]{2}/[0-9]{2}/[0-9]{4}$" style="width:65px;" Value="'; echo $f3;echo '" style="width:70px" disabled> </font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif"> <input type="text" name="start-time'; echo $i; echo '" pattern="[0-9]{2}:[00,15,30,45]{2}$" style="width:35px;" Value="'; echo $f4;echo '" style="width:35px"></font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif"> <input type="text" name="end-time'; echo $i; echo '" pattern="[0-9]{2}:[00,15,30,45]{2}$" style="width:35px;" Value="'; echo $f5;echo '" style="width:35px"></font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif"> <select name="location'; echo $i; echo '"><option value="'; echo $f6;echo '">'; echo $f6;echo '</option></font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif"> <select name="leavetype'; echo $i; echo '"><option value="'; echo $f7;echo '">'; echo $f7;echo '</option></font>
</td>
<td>
<font face="Arial, Helvetica, sans-serif"> <input type="text" name="rcomment'; echo $i; echo '" style="width:120px;" Value="'; echo $f8;echo '" style="width:70px"></font>
</td>
</tr> ';
++$i;}
if ($i=="0"){echo '<tr><td colspan="9"><p style="color: Green; font-size: 35px; font-weight:bold; text-align: center">All signed in-out correctly!</p></td></tr>';}
else if ($i > "0"){ echo '<tr><td colspan="9"><input name="Submit" type="Submit" Value="Update">';}
?>
如何设置第 2 行和后续行的值
$users_name = $_POST['name']; //员工姓名
$users_leavetype = $_POST['leavetype']; //休假类型(如:年假)
$users_date= date('d/m/Y', strtotime($_POST['rdate'])); //日期
$users_start = $_POST['开始时间']; //开始时间
$users_finish = $_POST['结束时间']; //结束时间
$users_location = $_POST['location']; //他们本来应该在的位置
$users_comment = $_POST['rcomment']; //管理员评论
我必须添加每个变量吗?或者有没有更简单的方法
注意:第二批代码来自另一个表单,因此不会针对此表单进行更改,只是显示我正在使用的格式,并且不确定如何根据需要进行编辑
感谢所有帮助
【问题讨论】:
标签: php mysql forms variables post