Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2006
    Location
    England
    Posts
    1,159
    Tokens
    0

    Latest Awards:

    Default Deleting Multiple Rows from a MySQL database with PHP

    Hey,

    For the past few days I've given my visitors the ability to delete multiple documents from their folder. Only recently did I realise it isn't working anymore and now it's driving me nuts. Here is the basis markup:

    Code:
    <?php
    include("t.php");
    include("u.php");
    $fetchimages = mysql_query("SELECT * FROM iuplogs WHERE username = '$_SESSION[username]' ORDER BY id DESC");
    ?>
    <form method="post" name="form">
    <table width="100%" cellpadding="0" cellspacing="0">
    <?
    if ($_POST['delete']) {
    foreach ($_POST['delete'] as $value) {
    mysql_query("DELETE FROM iuplogs WHERE id = '$value'");
    $fetchdelete = mysql_fetch_array(mysql_query("SELECT * FROM fuplogs WHERE id = '$value' ORDER BY id DESC LIMIT 1"));
    $explode = explode("/", $fetchdelete[url]);
    $filetodelete = "urs/$explode[4]";
    $delete = unlink($filetodelete);
    header("location: $url");
    }
    }
    ?>
      <tr>
       <td style="padding: 4px; padding-left: 12px;"><b>My Images</b></td>
      </tr>
    <?
    while ($image = mysql_fetch_array($fetchimages)) {
    ?>
      <tr>
       <td><input type="checkbox" name="delete[]" value="<?=$image[id];?>"></td>
      </tr>
    <?
    }
    ?>
      </tr>
      <tr>
       <td align="right" style="padding-top: 5px;"><input type="button" value="Select All" onClick="this.value=check(this.form)" name="selectsq" /><input type="submit" value="Delete Selected" name="submit" /></td>
      </tr>
    </table>
    </form>
    <?
    include("b.php");
    ?>
    I really can't see any problem with this. For the record, here is the error message which I receive when I select "Delete Selected".

    Warning: Invalid argument supplied for foreach() in /home/urload/public_html/test.php on line 10

    If I didn't mark any checkboxes then I would understand why I receive this error, but even when I do select one or more checkbox(s) I still receive this. Previously, I used error_reporting(E_ERROR); to hide the message if they selected "Delete Selected" without marking a checkbox.

    Any help would be very appreciated.

    Thanks in advance,
    mynameisoli
    Last edited by Halting; 04-09-2006 at 05:52 PM.
    REMOVED

    Edited by jesus (Forum Super Moderator): Please do not have text in your signature which is over size 4.

  2. #2
    Join Date
    Jun 2005
    Posts
    4,795
    Tokens
    0

    Latest Awards:

    Default

    Use do and while not for each.

  3. #3
    Join Date
    Apr 2006
    Location
    England
    Posts
    1,159
    Tokens
    0

    Latest Awards:

    Default

    Why? :S My method was working fine, and it still should be :S.
    REMOVED

    Edited by jesus (Forum Super Moderator): Please do not have text in your signature which is over size 4.

Posting Permissions

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