0

I am trying to allow a user to delete any one of these rows by clicking on the delete button for that respective row. Unfortunately, when they click delete, it deletes all of the rows. What am I doing wrong? Here is what the table looks like:

  • $metakey | $meta_value | Delete Button

    $metakey | $meta_value | Delete Button

    $metakey | $meta_value | Delete Button

<?php while($row=mysql_fetch_array($followerresult)){ $meta_key=$row["meta_key"]; $meta_value=$row["meta_value"];

echo "<table><tr> 
    <td>$meta_key</td> 
    <td>$meta_value</td> 
    <td><form ID='deleteform' method='POST'>
    <div id='mySubmit'>
    <input type='submit' name='Delete' value='Delete'>

    </form></td> 
</tr>"; 

 if (isset($_POST['Delete'])) {

                //SQL Delete

               echo $wp_login . " has been removed from access permissions";

}

echo "";

    ?>
4
  • 1
    And where is code, that performs delete operation? Commented Jul 16, 2013 at 18:34
  • Where is the SQL delete command? That is where the problem resides Commented Jul 16, 2013 at 18:36
  • @Vector i dont think that only this is the problem Commented Jul 16, 2013 at 18:38
  • Thanks for the help so far everyone. Here is the SQL Delete Function, this is for a wordpress site FYI. I am surprised to hear this is where the issue may be, would not have guessed it. $wpdb->query("DELETE FROM wp_usermeta WHERE meta_value = '$meta_value' AND user_id = '$meta_key'"); Commented Jul 16, 2013 at 20:47

2 Answers 2

1

The $meta_key and $meta_value are not part of the form. You need these to be input fields within the form and then use their values within the POST request. Rather than looping through and creating a table, instead loop through and create a full functional form with the correct inputs etc.

Sign up to request clarification or add additional context in comments.

Comments

0

You need to add hidden field to your HTML form.

<input type='hidden' name='meta_key' value='$meta_key' />

And, you must add WHERE clause to your SQL DELETE statement.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.