Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post

    While $i is smaller than var count, do.

    PHP Code:
     <?php 
    //**************************// 
    // Delete Selected Files    // 
    //**************************// 
    //Variables 
    $values $_POST['value']; 
    $i 0

    //Select checked items 
    if (isset($_POST['DelSel'])) { 
        
    $count count($values); 
        echo 
    "Deleted records: "
        while (
    $i $count) {         
            echo 
    "$values[$i], ";         
            
    //Delete record 
            
    $delete "DELETE FROM uploaded_files WHERE ID='$values[$i]'"
            
    $result mysql_query ($delete); 
            if (!
    $result
                { 
                die(
    'Error: ' .mysql_error()); 
                } 
            
    $i++; 
        } 
    //End While 

    ?>
    $_POST[‘value’] is a checkbox which has the value of the primary key in the database. So for an example, it would be 201.

    When the DelSel submit button is clicked the selected values are counted, whilst the number of values are higher then $i (0), records should be deleted for each value.

    But for some reason if I only select one checkbox, nothing is deleted. And if I select multiple checkboxes at least one row is left.
    Last edited by martynball; 01-19-2010 at 12:40 PM.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,864
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    ..and the question/conclusion?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    Nov 2007
    Posts
    682
    Thanks
    319
    Thanked 1 Time in 1 Post
    Sorry, I am sure I typed that part, instead of typing it up again I will edit my post with an email I just sent to a friend.

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,864
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    echo "$values[$i], ";
    //Delete record
    $delete = "DELETE FROM uploaded_files WHERE ID='$values[$i]'";
    Hope you don't get anything echoed for the highlighted line, above.
    Try
    PHP Code:
    $delete "DELETE FROM uploaded_files WHERE ID={$values[$i]}"
    Edit:
    I'd do something like
    PHP Code:
    if(isset($_POST['DelSel']) && is_array($_POST['DelSel'])){
        foreach(
    $_POST['DelSel'] as $value){
            if(
    ctype_digit($value))
                
    $del[]=$value;
        }
        if(
    is_array($del)){
            
    $sql="DELETE FROM uploaded_files WHERE ID in (".implode(',',$del). ")";
            
    mysql_query ($sql) or die(mysql_error()); 
        }
            

    Last edited by abduraooft; 01-19-2010 at 01:21 PM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    martynball (01-19-2010)


  •  

    Posting Permissions

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