Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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 "";

    ?>
share|improve this question
1  
And where is code, that performs delete operation? –  Krab Jul 16 '13 at 18:34
 
Where is the SQL delete command? That is where the problem resides –  Vector Jul 16 '13 at 18:36
 
@Vector i dont think that only this is the problem –  steven Jul 16 '13 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'"); –  Tom Jul 16 '13 at 20:47
add comment

2 Answers

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.