gpt4 book ai didi

php - 为什么执行查询时只更新/删除表的最后一行?

转载 作者:行者123 更新时间:2023-11-29 23:19:36 25 4
gpt4 key购买 nike

这对我来说真是个谜!哈哈。为什么当我执行查询时只有表的最后一行被更新/删除?代码正在运行,只是,只能修改最后/最近的记录。我以前遇到过这个问题,第二天我重新启动电脑时就解决了[好吧,我不知道它是怎么发生的哈哈]。现在它又成为我的问题。

有人可以帮我解决这个问题吗...

这是我的AdminPAevaluation.php页面:

这是HTML部分:

<?php
$selectquery="select * from tbl_annualevaluation;";
$selectrs=mysqli_query($con,$selectquery) or die ("Cannot execute query.");
$selectrows=mysqli_fetch_array($selectrs);
?>
<tr>
<th>DESCRIPTION</th>
<th>GRADE (%)</th>
<th>SALARY APPRAISAL (%)</th>
<th>UPDATE
</th>
<th>DELETE</th>
</tr>

这是PHP部分:

<?php do{ ?>

<tr>
<td><input type="text" value="<?php echo $selectrows['description'];?>" name="txtdescription" class="textbox1" /></td>
<td><input type="text" value="<?php echo $selectrows['grade'];?>" name="txtgrade" class="textbox1" /></td>
<td><input type="text" value="<?php echo $selectrows['salaryAppraisal'];?>" name="txtsalaryAppraisal" class="textbox1" /></td>
<td><input type="submit" value="UPDATE" class="button1" name="update"/></td>
<td><input type="submit" value="DELETE" class="button1" name="delete"/></td>
</tr>
<input type="hidden" value="<?php echo $selectrows['idtbl_annualevaluation'];?>" name="txtidtbl_annualevaluation" />

<?php } while($selectrows=mysqli_fetch_array($selectrs)); ?></table>
</form>
</center>
</body>
</html>

<?php
$descId=$_POST['txtidtbl_annualevaluation'];
$txtdesc=$_POST['txtdescription'];
$txtgrade=$_POST['txtgrade'];
$txtsalaryAppraisal=$_POST['txtsalaryAppraisal'];

//this is the block codes for insert
if(isset($_POST['insert'])){
$insertdesc="insert into tbl_annualevaluation (description) values ('$_POST[new]');";
$insertdescrs=mysqli_query($con,$insertdesc) or mysqli_error();
header("location:AdminPAevaluation.php");
}

//this is the block codes for delete.
if(isset($_POST['delete'])){

这部分,我认为我的代码是正确的,名称也放置正确,所以我不知道为什么它不能正常工作......嗯嗯嗯

$deletedesc="delete from tbl_annualevaluation where idtbl_annualevaluation='$descId';";
$deletedescrs=mysqli_query($con,$deletedesc);
header("location:AdminPAevaluation.php");

}
if(isset($_POST['update'])){
$updatedesc="update tbl_annualevaluation set description='$txtdesc', grade='$txtgrade', salaryAppraisal='$txtsalaryAppraisal' where idtbl_annualevaluation='$descId';";
$updatedescrs=mysqli_query($con,$updatedesc) or mysqli_error();
header("location:AdminPAevaluation.php");
}
?>

我非常确定列名、表和所有内容都已正确/适本地指定。

最佳答案

因为它们都是同一表单的一部分,所以它可能只读取最后一个隐藏值。您忘记让循环在开始时创建一个新表单。

<?php do{ ?>
<form action="index.php" method="POST">
<tr>
<td><input type="text" value="<?php echo $selectrows['description'];?>" name="txtdescription" class="textbox1" /></td>
<td><input type="text" value="<?php echo $selectrows['grade'];?>" name="txtgrade" class="textbox1" /></td>
<td><input type="text" value="<?php echo $selectrows['salaryAppraisal'];?>" name="txtsalaryAppraisal" class="textbox1" /></td>
<td><input type="submit" value="UPDATE" class="button1" name="update"/></td>
<td><input type="submit" value="DELETE" class="button1" name="delete"/></td>
</tr>
<input type="hidden" value="<?php echo $selectrows['idtbl_annualevaluation'];?>" name="txtidtbl_annualevaluation" />
</form>

<?php } while($selectrows=mysqli_fetch_array($selectrs)); ?></table>

关于php - 为什么执行查询时只更新/删除表的最后一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27440231/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com