Re: checkbox deletions
| From: | Hans H. Anderson | Date: | Wed, 13 Sep 2000 19:21:01 +0000 |
| Subject: | Re: checkbox deletions | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-16624@lists.php.net to get a copy of this message | ||
Richard,
Checkboxes that are checked will return the value of the checked box if
checked, but won't exist if it's not.
so if you have these checked in your script:
ID2Delete[]
ID2Delete[]
ID2Delete[]
ID2Delete[]
In your action page you'll have a 4 item array named ID2Delete.
Connect to your DB, then loop through the array to delete the bunch, or
you can build a delete list and use the IN() command in MySQL:
for($i=0;$i<count($ID2Delete);$i++) {
$result = mysql_query("delete from table where ID = $ID2Delete[$i]");
}
OR
$IDs = implode(",",$ID2Delete);
$result = mysql_query("delete from table where ID IN ($IDs)");
Hope that helps,
Hans
On Wed, 13 Sep 2000, Richard Bradley wrote:
> I've developed this script but it does not delete the items from mysql
> database that are marked Checked on the form. Any suggestions, maybe
> it's because I need to write to the database "checked" upon submitting
> the form.
>
> <?php
>
> $connection =
> mysql_connect("mysql.myhost.net","myusername","XXXXXX")
> or die ("Couldn't open connection to the server");
>
> $db = mysql_select_db("mainyl_db", $connection) or die ("Couldn't
> connect to the database");
>
>
> $sql = "DELETE FROM FORM_EMAILS WHERE DELETE_CONTACT = 'CHECKED'";
>
> $sql_result = mysql_query($sql,$connection) or die ("Could't execute query.");
>
> header("Location:
> http://web5.yourlink.net/yourlink/formdata/delete_items.php");
>
> ?>
>
> Richard
> Senior Site Developer/YourLink, inc.
>
>
--
Hans Anderson -=- me@hansanderson.com | PHP, MySQL, Flash, Audio
Free PHP Stuff at http://www.hansanderson.com/php/:
All PHP Full Text Search Engine (nothing but PHP required)
Time Tracking Software (track your hours for clients)
All PHP Simple Crypto (If Blowfish=Pentagon, Crypto=Boy Scouts)
PHP Browser Class (Like Perl's LWP)