On Mon, 3 Feb 2003, Tomator wrote:
> User "Mr. Bungl3" <[EMAIL PROTECTED]> wrote:
> > I'm trying to delete a some records from a table with checkboxes and then
> i
> > have this code:
> >
> $sql="DELETE FROM divx where id=".$del[$i]."";
>
> Great idea, but when checkbox is checked, variable of it's name just becomes
> true (doesn't get value of it's index anyway). So, I'd write it this way:
>
> if ($del[$i]) {
> $sql="DELETE FROM divx WHERE id='".$i."'";
> mysql_query...;
> }
By default a checked checkbox has the value of 'on' but this
can be changed to anything. So for example:
<input type="checkbox" name="id[]" value="444">
One can use IN to delete them all, for example:
$ids = implode(',', $_POST['id']);
$sql = "DELETE FROM divx
WHERE id IN ($ids)";
Anyway, you mention $del so you should make sure that
this variable even exists as for it to exist automatically
you need the register_globals directive to be on. Odds
are it's off and you should code with it off. I assume
we are using method="POST" in the form. See:
http://www.php.net/variables.external
Debugging101 would have you do: print $sql;
And lastly, posting a TON of code won't get you very
far. I just ignored it and based my response on the
one above.
Regards,
Philip Olson
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php