Delete Usings Checkboxes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • adamjblakey
    New Member
    • Jan 2008
    • 133

    Delete Usings Checkboxes

    Hi,

    I have a system in place like an inbox which people can select a check box next to each message and then press delete which will delete the selected.

    <input name="delete" type="checkbox" id="delete" value="<?php print $rows['id']; ?>" />

    This is my code:

    [PHP]
    $delete = $_POST['delete'];

    foreach ($delete as $deleted) {
    $sql = mysql_query("DE LETE * FROM messages WHERE id='$deleted'") ;

    }
    [/PHP]

    This is not working though. Any ideas?

    Cheers,
    Adam
  • ajcolburn
    New Member
    • Jan 2007
    • 11

    #2
    Originally posted by adamjblakey
    Hi,

    I have a system in place like an inbox which people can select a check box next to each message and then press delete which will delete the selected.

    <input name="delete" type="checkbox" id="delete" value="<?php print $rows['id']; ?>" />

    This is my code:

    [PHP]
    $delete = $_POST['delete'];

    foreach ($delete as $deleted) {
    $sql = mysql_query("DE LETE * FROM messages WHERE id='$deleted'") ;

    }
    [/PHP]

    This is not working though. Any ideas?

    Cheers,
    Adam
    Hi there,
    Try replacing 'delete' with 'delete[]' as the name to post checkbox values as an array, eg:

    [CODE=php]
    <input name="delete[]" type="checkbox" id="delete" value="<?php print $rows['id']; ?>" />
    [/CODE]

    Comment

    • adamjblakey
      New Member
      • Jan 2008
      • 133

      #3
      I have just tried this and it appears that it does not work :( Any ideas?

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        echo the deleted out, to see if its being passed.
        [php]
        $delete = $_POST['delete'];

        foreach ($delete as $deleted)
        {
        echo $deleted . "<br />";
        // $sql = mysql_query("DE LETE * FROM messages WHERE id='$deleted'") ;
        }
        [/php]

        Comment

        • adamjblakey
          New Member
          • Jan 2008
          • 133

          #5
          No nothing is being passed :S

          Why do you think that is?

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            Post the code for your form please :)

            We'll have a harder look!

            Comment

            • adamjblakey
              New Member
              • Jan 2008
              • 133

              #7
              Ok great, i am using smarty so if the tags look weird thats why.

              Code:
              <form action="send-message-process.php?type=delete" method="post" name="frm1" id="frm1">
                      
                           <input type="submit" name="Submit3" value="Delete" class="buttons" />
                   
              		<table width="100%" border="0" cellspacing="0" cellpadding="3">
                                              <tr>
                                                <td width="4%" height="30" background="images/red-nav-bar.jpg"><h2 class="white">
                                                    <input name="allbox2" type="checkbox" id="allbox2" value="checkbox" onclick='checkedAll(frm1);'/>
                                                </h2></td>
                                                <td colspan="2" background="images/red-nav-bar.jpg"><h2><span class="white">Sender</span></h2>                                    </td>
                                                <td width="61%" background="images/red-nav-bar.jpg"><h2><span class="white">Subject</span></h2></td>
                                                <td width="15%" background="images/red-nav-bar.jpg"><h2 class="white">Date</h2></td>
                                              </tr>
              						        {php} 
              						        $sqls = mysql_query("SELECT * FROM messages WHERE profileid = '$_COOKIE[id]'"); 
              						        while($rows = mysql_fetch_array($sqls)){ 
              						        {/php}
              						        <tr>
                                                      <td bgcolor="#FCE4E5"><input name="delete[]" type="checkbox" id="delete[]" value="{php} print $rows['id']; {/php}" /></td>
              						          <td width="10%" bgcolor="#FCE4E5"> {php} 
              						            $sql = mysql_query("SELECT * FROM users WHERE id = '$rows[userid]'"); 
              						            while($row = mysql_fetch_array($sql)){ 
              						            {/php} <a href="message-details.php?id={php} print $row['id']; {/php}"><img src="profile/thumbs/{php} print $row['image_1']; {/php}" width="50" height="40" border="0" /></a> {php} } {/php} <br />                                        </td>
              						          <td width="10%" bgcolor="#FCE4E5"><a href="message-details.php?id={php} print $row['id']; {/php}">{php} print $rows[username]; {/php}</a></td>
              						          <td bgcolor="#FCE4E5"><a href="message-details.php?id={php} print $rows[id]; {/php}">{php} print $rows[title]; {/php}</a></td>
              						          <td bgcolor="#FCE4E5">{php} print $rows['sdate']; {/php}</td>
              					            </tr>
              						        {php} } {/php}
              					          </table>
              						      <p><a href="#" onclick='checkedAll(frm1);'>Select All</a> / <a href="#" onclick='checkedAll(frm1);'>Unselect All</a> </p>
              					
                     <input type="submit" name="Submit22" value="Delete" class="buttons" />
                                       
              						      </p>
              					        </form>

              Comment

              Working...