The update feature that im working on is confusing me with the undefined index that I got. I had a button from a page called model.php and it links to the update_model.php page. The error that I got is Undefined index: idx when i press the confirm the update in my update_model page. My record does not get updated in the database as well but the success message does appear. I have already declared the idx variable using get method, but why does it still say that it is an undefined index? Is it not getting anything?
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>
button in model.php:
<button class="btn-success btn"> <a href="update_model.php?idx=<?php echo $rows['model_id']; ?>" class="text-white"> Update </a> </button>