Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your logic is in the right place, but not executed correctly. You're trying to see if a user/member has been deleted by doing:</p> <pre><code>$res = mysqli_query($con,$sql); if($res) { </code></pre> <p>However, <a href="http://php.net/mysqli_query" rel="nofollow"><code>mysqli_query()</code></a> will return <code>true</code> if the statement executed properly for a <code>DELETE</code> - it doesn't matter if it deletes rows or not.</p> <p>What you'll want to do is utilize <a href="http://docs.php.net/manual/en/mysqli.affected-rows.php" rel="nofollow"><code>mysqli::$affected_rows</code></a>:</p> <pre><code>$res = mysqli_query($con, $sql); if (mysqli_affected_rows($con) == 1) { echo "member with ID of ".$member_id." has been removed from members table"; } else { echo "member was not deleted"; } </code></pre> <p>This will check if there was a single record affected by your <code>DELETE</code> statement (assuming your member-IDs are unique; if not, you could use <code>&gt;= 1</code> instead). If there was one, well, it was removed!</p> <p><strong>Side Note</strong> (not answer specific)<br> You should drop your <code>fix_string()</code> method and opt for <code>mysqli</code>'s prepared statements which will auto-sanitize the input for you. You can try the following for your existing code:</p> <pre><code>require("connect.php"); $member_id = (!empty($_POST['member_id']) ? $_POST['member_id'] : ''); // prepare the statement $stmt = mysqli_prepare($con, 'DELETE FROM members WHERE member_id = ?'); // bind the id mysqli_stmt_bind_param($stmt, "s", $member_id); // execute the statement mysqli_stmt_execute($stmt); if (mysqli_affected_rows($con) == 1) { echo "member with ID of ".$member_id." has been removed from members table"; } else { echo "member was not deleted"; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload