i have a page called member.php
in php
section, i write this code :
if(isset($_POST['delete-btn'])) {
$uid = $_GET['delete'];
$user->delete($uid);
header("Location: member?deleted");
}
in form in html
section i write this code :
<form method="post">
<input type="hidden" name="uid" value="<?php echo $row_user['user_id']; ?>" />
<button type="submit" class="btn" name="delete-btn">Delete</button>
</form>
$user->delete($uid);
goes to class.user.php
and the following code is :
public function delete($uid) {
$stmt = $this->db->prepare("DELETE FROM members where user_id=:uid");
$stmt->bindparam(":uid", $uid);
$stmt->execute();
return true;
}
When i try to use this code, the button disappear :
<?php
if(isset($_GET['delete'])) {
?>
<form method="post">
<input type="hidden" name="uid" value="<?php echo $row_user['user_id']; ?>" />
<button type="submit" class="btn" name="delete-btn">Delete</button>
</form>
<?php
}
?>
My question is, when i try to delete, the page refreshed and get member?deleted
isn't that mean the affected row should be deleted ? But nothing happen, no one row deleted. Maybe what make this wrong is in the form, but i don't know what is it..
you have used post method. so for getting uid you have to use
$uid = $_POST['uid'];
instead of
$uid = $_GET['delete'];