所以我一直在为我父亲的朋友工作,所以他可以保持他的生意。我一直在使用While循环打印出可以输入的'任务'表在网站上,但是当我改变任务的状态时,它没有这样做?
我确信这是我获取用于查找需要更新的记录的ID的方式,但我认为我的方法正确。首先,除了我的伪劣编码之外还有什么明显的东西吗?其次,有没有更好的方法来获取ID或缺乏更新的推理?非常感谢! HTML - 页面
<table class="tasktable">
<tr>
<th style="text-align: center; width: 100px ">Job Number (ID)</th>
<th style="text-align: center; width: 100px">VRM</th>
<th style="text-align: center; width: 175px;">Date Arrived</th>
<th style="text-align: center;">Work</th>
<th style="text-align: center; width:200px;">Customer</th>
<th style="text-align: center; width: 250px;">Task Progress</th>
</tr>
<?php
include 'Login-System/db.php';
$query = 'SELECT * FROM outstanding WHERE taskprogress = "New" OR taskprogress = "In Progress" ORDER by id ASC';
$result = mysqli_query($conn, $query);
if($result):
if(mysqli_num_rows($result)>0):
while($tasks = mysqli_fetch_assoc($result)):
?>
<tr>
<td style="text-align: center;"><h4 name="jobnumberid"><?php echo $tasks['id'];?></h4></td>
<td style="text-align: center;"><h4><?php echo $tasks['VRM'];?></h4></td>
<td style="text-align: center;"><h4><?php echo $tasks['datearrived'];?></h4></td>
<td style="text-align: center;"><h4><?php echo $tasks['work'];?></h4></td>
<td style="text-align: center;"><h4><?php echo $tasks['customer'];?></h4></td>
<td>
<form action="SQL/taskchange.php" role="form" method="post" id="taskchange">
<select name="taskchanger" id="taskchanger" style="margin-top:6px;
width: 150px; float:left" class="form-control">
<option value="#"><?php echo $tasks['taskprogress'];?></option>
<?php
if ($tasks['taskprogress']== "New") {
echo '<option value="In Progress" class="form-control">In Progress</option>
<option value="Complete" class="form-control">Complete</option>';
} else { if ($tasks['taskprogress']== "In Progress") {
echo '<option value="New" class="form-control">New</option>
<option value="Complete" class="form-control">Complete</option>';
} else {
echo '<option value="New" class="form-control">New</option>
option value="In Progress" class="form-control">In Progress</option>';
}
}
?>
</select>
<button name="save" id="save" class="form-control" style="width: 75px; float:right;margin-top: 6px">Save</button>
</form>
</td>
</tr>
<?php
endwhile;
endif;
endif;
?>
</table>
PHP - 插入数据库的位
<?php
if(isset($_POST['save'])){
include '../Login-System/db.php';
$id = mysqli_real_escape_string($conn, $_POST['jobnumberid']);
$newtask = mysqli_real_escape_string($conn, $_POST['taskchanger']);
$sql = "UPDATE outstanding SET taskprogress = '$newtask' WHERE id = '$id'";
mysqli_query($conn, $sql);
header("Location: ../outstanding.php?updated");
exit();
} else {
header("Location: ../outstanding.php?whoops");
exit();
}