-3

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..

Manoj Sharma
  • 1,467
  • 2
  • 13
  • 20
Gilang Rizkie
  • 111
  • 1
  • 10
  • sounds like "undefined index" to me. – Funk Forty Niner Jan 05 '17 at 12:12
  • Do you meant to use $_POST['uid'] instead Is your url just member?delete or is it member?delete=123/ – 2bigpigs Jan 05 '17 at 12:13
  • @Fred-ii- nothing error showing.. – Gilang Rizkie Jan 05 '17 at 12:13
  • you are using POST method and checking it with GET – Nishant Nair Jan 05 '17 at 12:14
  • @NishantNair i tried to change that to `$uid = $_POST['delete'];` and still not change anything – Gilang Rizkie Jan 05 '17 at 12:17
  • ` $uid = $_POST['uid'];` use this in your ajax. Because you are using name as id in your form – Nishant Nair Jan 05 '17 at 12:19
  • i change to this `$uid = $_POST['uid'];` and its work! Thanks! – Gilang Rizkie Jan 05 '17 at 12:23
  • @Fred-ii- why you are so sensitive ? I'm asking because i don't know yet how to solve it... My code and another is different.. Marked this as duplicate isn't the problem to me. I know your knowledge is more than me. – Gilang Rizkie Jan 05 '17 at 12:26
  • *"i change to this $uid = $_POST['uid']; and its work!"* - well guess what... "undefined". what's the argument about and what's this "sensitivity stuff"? lol – Funk Forty Niner Jan 05 '17 at 12:27
  • @Fred-ii- U never helping me to solve problem, u just looking for someone mistake.. Look how the others helping, looking for the problem and solve it where the problem is, an look at u ??? Tag problem or just another "LITTLE" problem... – Gilang Rizkie Jan 05 '17 at 12:30
  • Look, if you have a problem with how Stack works, take it up on meta and argue with them there. I can tell you right now, you're more than likely going to be shot down, good luck. – Funk Forty Niner Jan 05 '17 at 12:31
  • @Fred-ii- my problem with you, not with stack... Do you see Bhavik ? S/He, just answered my question... And this wht i need... Not a lot of talking like you – Gilang Rizkie Jan 05 '17 at 12:33
  • please stop, just stop and don't reping me or I'll flag as being too chatty/annoying, I am done here. Enjoy coding, it's a lot more fun than crying over spilt milk. – Funk Forty Niner Jan 05 '17 at 12:35
  • @Fred-ii- ok, im so sorry, i didn't mean that.. i just hating u never answer quickly :) thanks before for not ignoring my post ;) – Gilang Rizkie Jan 05 '17 at 12:39

1 Answers1

2

you have used post method. so for getting uid you have to use

$uid = $_POST['uid'];

instead of

$uid = $_GET['delete'];

Bhavik
  • 495
  • 2
  • 10