SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru Marc's Avatar
    Join Date
    Nov 2000
    Location
    New York
    Posts
    765
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dealing with checkboxes...

    Hi, I've looked around the net, and I've searched this forum, but I can't seem to figure out how to do this.. so I'm going to ask here.

    I have a page that displays a buncha values stored in a db, with a checkbox for delete next to them:

    --------------------------
    [] | A user listed in db |
    ---|---------------------|
    [] | A user listed in db |
    ---|---------------------|
    [] | A user listed in db |
    ---|---------------------|
    [] | A user listed in db |
    --------------------------


    Just imagine that each [] represents a checkbox

    Now, when they click off one, two, or multiple checkboxes, I want to delete the corresponding user..

    I have
    PHP Code:
    <input type=checkbox name="del[]" value="<? echo $pid?>">
    for the checkbox.. where $pid is the value of the id column of the row that contains "A user listed in db".

    I am trying this to process it (found it online)..
    PHP Code:
    if (count($del) > 1) { 

    for (
    $i=0;$i<count($del);$i++) { 
    $result[$i] = mysql_query("DELETE FROM posts WHERE id = '$del[$i]'"); 

    But that gives me an error.. it says "parse error" and line 68, but line 68 is the very last line of the file.. a common error.

    Thanks in advance! I hope I explained my problem well..
    Last edited by Marc; Oct 19, 2001 at 17:49.
    Marc Gugliuzza
    marc.gugliuzza.com



  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to close your if() clause

    PHP Code:
    if (count($del) > 1) { 

       for (
    $i=0;$i<count($del);$i++) { 
          
    $result[$i] = mysql_query("DELETE FROM posts WHERE id = '$del[$i]'"); 
          }
      } 
    Incidentally to allow yourself less of a strain of all those queies.


    PHP Code:
    if (count($del)) { 
    $str implode(",",$del);
    $result mysql_query("DELETE FROM posts WHERE id IN($str)"); 
      } 
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Guru Marc's Avatar
    Join Date
    Nov 2000
    Location
    New York
    Posts
    765
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    19-Oct-2001 07:40PM posted.
    19-Oct-2001 07:49PM reply.

    Oh my goodness. Thats all I have to say.

    I once again, made the stupidest mistake possible.
    Your code, freddy, is much better than that other one (which I copied off a php tutorial site).

    Thank you so much
    Marc Gugliuzza
    marc.gugliuzza.com




Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •