Jump to content

Recommended Posts

Here is my code

while($row = mysql_fetch_array($result2))
  {
  echo "<form class='small' name='login' method='post' action='delete.php?<?php echo SID?>'>";
  echo "<tr>";
  echo "<td>";
  echo "<input type='checkbox' name='delete' value='$del' /></td>";
  echo "<td>" . $row['NAME_FIRST'] . "</td>";
  echo "<td>" . $row['NAME_LAST'] . "</td>";
  echo "<td>" . $row['EMAIL'] . "</td>";
  echo "<td>" . $row['PASSWORD'] . "</td>";
  echo "<td>" . $row['COMPANY'] . "</td>";
  echo "<td>" . $row['ADDRESS1'] . "</td>";
  echo "<td>" . $row['ADDRESS2'] . "</td>";
  echo "<td>" . $row['ADDRESS3'] . "</td>";
  echo "<td>" . $row['COUNTY'] . "</td>";
  echo "<td>" . $row['COUNTRY'] . "</td>";
  echo "<td>" . $row['POST_CODE'] . "</td>";
  echo "<td>" . $row['PHONE'] . "</td>";
  echo "<td>" . $row['VALIDATE'] . "</td>";
  echo "<input type='checkbox' name='validate' value='$val' /></td>";
  echo "<td>" . $row['ID'] . "</td>";
  
  echo "</tr>";
  }
echo "</table>";


echo "<input type='submit' name='Submit' value='delete' />";
echo "<input type='submit' name='Submit' value='validate' />";
echo "</form>";

 

A php generated table which loops through my database which lists everything from the database table. Also it has two sets of check boxes.

 

1. I want it so that when the delete checkbox is selected and the delete button is clicked it deletes this entry from the database.

 

2. There is a 2nd checkbox $val I want when this is checked and the validate button pressed, for the check box to stay checked and the entry in the validate colum to say 'yes' when unchecked to say 'no' default value 'no'

 

All help is much appreciated

 

Thank you in advance

Link to comment
https://forums.phpfreaks.com/topic/156492-delete-using-checkbox/
Share on other sites

1)

 

<input type="checkbox" name="delete" value="1" />
<?php
if (sizeof($_POST) && isset($_POST['delete']) && $_POST['delete'] === 1) {
    ..delete entry..
}

 

2) Use the hidden value technique

 

<input type="hidden" name="validate" value="no" />
<input type="checkbox" name="validate" value="yes" />

 

when checked will say yes if not will say no

I need it to update the database too with either yes or no, so

 

update table name 
SET validate=yes
where ID = $(the checked boxes) 

 

and

 

update table name 
SET validate=no
where ID = $(the checked boxes) 

 

also where in my code do I put

input type="checkbox" name="delete" value="1" />
<?php
if (sizeof($_POST) && isset($_POST['delete']) && $_POST['delete'] === 1) {
    ..delete entry..
}

 

Sorry I'm an annoying newbee!

add another field in your form which says:

 

<input type="hidden" name="id" value="<?php print $row['id']; ?>" />

 

then you can do:

 

UPDATE tableName SET validate = $_POST['validate'] WHERE id = $_POST['id']

 

also where in my code do I put 

 

well that is more difficult, not in the while that is for certain :)

 

Sorry I'm an annoying newbee!

 

And i am here to entertain you :)

Ok, I'm still having problems with deleting from my db through php code:

 

 //Delete the customer rows (only if the form has been submitted)
  
      if (isset($_POST['submit']))
    {
     foreach ($_POST['todelete'] as $delete_id) {
     $query="DELETE FROM login WHERE ID = $delete_id";
     mysql_query($query) or die ('Error in query: ' .mysql_errno() . mysql_error());
  
     }
echo 'Customer(s) removed.<br />';
     }    
  echo"<form>";
  
     // Display the customer rows with checkboxes for deleting
     $query="SELECT * FROM login";
     $result = mysql_query($query);
     while ($row = mysql_fetch_array($result)){  
     echo '<input type="checkbox" value="' . $row['id'] .'"name="todelete[]" />';
     echo $row['NAME_FIRST'];
     echo ' '.$row['NAME_LAST'];
     echo ' '.$row['EMAIL'];
     echo '<br />';  
  
  
    }    


echo "<input type='submit' name='submit' value='submit' />";
echo "</form>";

 

displays fine but does not do anything!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.