我想在一次提交中更新表格行。但我不知道該怎麼做。更新提交中的多行
這是我的代碼
<form method="POST" action="<?php $_PHP_SELF ?>">
<div class="col-md-7" style="margin-left:370px; height:auto;">
<h3>Service-Level-Agreement</h3>
<?php
$query = "select * from tblsla";
$request = mysql_query($query)or die(mysql_error());?>
<table class="table table-hover" style="width:auto;">
<tr>
<th>Category</th>
<th>Easy</th>
<th>Moderate</th>
<th>Difficult</th>
<th></th>
</tr>
<?php while($row = mysql_fetch_array($request)){
?>
<tbody>
<tr>
<td><?php echo $row['category']; ?></td>
<td><input type="text" class="form-control" style="width:50px;" name="easySla"/></td>
<td><input type="text" class="form-control" style="width:50px;" name="modSla"/></td>
<td><input type="text" class="form-control" style="width:50px;" name="difSla"/></td>
<td>Days</td>
</tr>
</tbody>
<?php
}
?>
</table>
<input type="submit" name="submit" id="submit" value="Edit SLA" class="btn btn-success"/>
</div>
<input type="hidden" name="idUser" value="<?php echo $row['id'];?>" />
</form>
PHP
<?php
$easy = $_POST["easySla"];
$mod = $_POST["modSla"];
$diff = $_POST["diffSla"];
if(is_int($easy) AND is_int($mod) AND is_int($diff)){
echo " Invalid Inputs ";
}
else
{
$sql = "UPDATE tblsla SET easySLA = '$easy', modSLA = '$mod', difSLA = '$diff' WHERE id = '$id'";
if(isset($_POST['submit'])){
$success = mysql_query($sql) or die (mysql_error());
}
if ($success == TRUE){
?>
<script>
alert('You have successfully update account.');
</script>
<?php
}
}
?>
這是像什麼,我希望發生的
太謝謝你了!
你有severals輸入具有相同的名稱。你需要使用數組作爲輸入名稱。 –