Re: Re: Can anyone help me? i'm getting crazy... : |
| From: | Philip Olson | Date: | Mon, 03 Feb 2003 22:40:51 +0000 |
| Subject: | Re: Re: Can anyone help me? i'm getting crazy... : | | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-134191@lists.php.net to get a copy of this message | ||
On Mon, 3 Feb 2003, Tomator wrote:
> User "Mr. Bungl3" <mrbungle@netcabo.pt> 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