Results 1 to 4 of 4

Thread: IDs Over 10 Being Split

  1. #1
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default IDs Over 10 Being Split

    I have made a delete script with multiple delete. Everything runs great until the delete ID being fed hits 10 or more, then it splits it into 1 and 0 instead of 10. Here is the delete PHP:
    PHP Code:
    ###### If Delete Was Hit ######
                
    else if ($_POST['delete']) {    
                        
    $links mysql_query("SELECT * FROM `cms_nav` ORDER BY id ASC") or die ("Error Getting Links! \n <br /> \n" .mysql_error()); 
                        
    $chk mysql_num_rows($links);
                    for (
    $i=0$i<$chk$i++) {
                        
    $del_id $checkbox[$i];
                        
    $del mysql_query("DELETE FROM `cms_nav` WHERE id = '$del_id'") or die ("Error Deleting Selected! \n<br />\n" .mysql_error());
                        echo(
    'Del ID: '.$del_id.' ');
                    }
                    echo(
    '<meta http-equiv="refresh" content="2;URL=nav.php" /> <div class="message">The selected links have been deleted</div>'); 
                }
                
    ###### ################# ###### 
    When I this code added to the script and the ID to be deleted is 10, it echos Del ID: 1 Del ID: 0
    Code:
    echo('Del ID: '.$del_id.' ');
    Here is the HTML sending the information:
    HTML Code:
    <input type="checkbox" name="checkbox" value="<?php echo $l['id']; ?>" />
    Anyone know why it is doing this?

    Thanks in advance
    Thanks DD, you saved me countless times

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It isn't an array. You're looping over the characters of the string here:
    Code:
                    for ($i=0; $i<$chk; $i++) {
                        $del_id = $checkbox[$i];
    In PHP, if you want an array from POST data the element names have to end with [].
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey View Post
    It isn't an array. You're looping over the characters of the string here:
    Code:
                    for ($i=0; $i<$chk; $i++) {
                        $del_id = $checkbox[$i];
    In PHP, if you want an array from POST data the element names have to end with [].
    So the code should be
    Code:
    <input type="checkbox" name="checkbox[]" value="<?php echo $l['id']; ?>" />
    or do you mean:
    PHP Code:
    $del_id $checkbox[$i][]; 
    Thanks
    Thanks DD, you saved me countless times

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <input type="checkbox" name="checkbox[]" value="<?php echo $l['id']; ?>">
    Don't use XHTML on the web right now: http://www.webdevout.net/articles/beware-of-xhtml
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •