我正在使用的更新功能使我感到困惑,因为我得到的未定义索引。我有一个来自名为model.php的页面的按钮,它链接到update_model.php页面。我收到的错误是未定义的索引:idx,当我按下update_model页面中的确认更新时。我的记录也不会在数据库中更新,但是会显示成功消息。我已经使用get方法声明了idx变量,但是为什么仍然说它是未定义的索引呢?它什么都没得到吗?
update_model.php:
<?php
$idd = $_GET['idx'];
$query = $conn->query("SELECT * FROM model WHERE model_id='$idd' limit 0,1");
$row = $query->fetch_assoc();
if(isset($_POST['updateBtn'])){
$id = $row['model_id'];
$model = $_POST['model'];
$result = $conn->query("UPDATE model SET model='".$model."' WHERE model_id='".$id."'");
if($result){//success update message
?>
<div class="alert alert-success alert dismissible" role = "alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
<strong id="alert">Success!</strong>Your data has been updated.
</div>
<?php
}
}
?>
<form action="update_model.php" method="post">
<table>
<tr>
<td> Model </td>
<td>
<input type="text" name="model" placeholder="<?php echo $row['model'] ?>" required>
</td>
<td>
<button name="updateBtn" type="submit" class="btn-success btn"> Update </button>
</td>
</tr >
</table>
</form>
model.php中的按钮:
<button class="btn-success btn"> <a href="update_model.php?idx=<?php echo $rows['model_id']; ?>" class="text-white"> Update </a> </button>
答案 0 :(得分:1)
从此处更改代码
<form action="update_model.php" method="post">
到
<form action="update_model.php?idx=<?=$idd;?>" method="post">