Re: Editing DB entries via form
| From: | Darryl Friesen | Date: | Tue, 27 Mar 2001 16:22:41 +0000 |
| Subject: | Re: Editing DB entries via form | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-7881@lists.php.net to get a copy of this message | ||
> Say a person checks the 1, 5, and 9 check boxes and hits delete.
> How do I know in the myEditNews.php file that those particular boxes
> were checked?? When I figure this out, I will use a loop to delete
> the news items one at a time from the database (unless there is a
> better way).
>
> My understanding of check boxes is that they are not sent from the
> form unless they are checked.
Correct.
> Am I making this hard on myself?
Yes. There's no need to have all the JavaScript and hidden fields.
<INPUT TYPE="checkbox" NAME="newsItem[]" VALUE="Item1"> Item
1<BR>
<INPUT TYPE="checkbox" NAME="newsItem[]" VALUE="Item2"> Item
2<BR>
<INPUT TYPE="checkbox" NAME="newsItem[]" VALUE="Item3"> Item
3<BR>
Notice the naming convention of the HTML checkbox elements! It's important
to have the square (array) brackets. Now, when user clicks the submit
button, your PHP script will have a newsItem array that will contain the
VALUEs from above for all those that were checked. (i.e. an array containing
'Item1' and 'Item3' if #1 and 3 were checked).
Now loop through the newsItem array deleting those records, or create a
single query to delete them all at once (off the top of my head, I _think_
something like "DELETE FROM table WHERE Item='Item1' OR Item='Item3'"
will
work)
- Darryl
----------------------------------------------------------------------
Darryl Friesen, B.Sc., Programmer/Analyst Darryl.Friesen@usask.ca
Education & Research Technology Services, http://gollum.usask.ca/
Department of Computing Services,
University of Saskatchewan
----------------------------------------------------------------------
"Go not to the Elves for counsel, for they will say both no and yes"