www.webdeveloper.com
Results 1 to 2 of 2

Thread: Warning: Variable passed to each() is not an array or object in

  1. #1
    Join Date
    Jul 2013
    Posts
    2

    Warning: Variable passed to each() is not an array or object in

    Hi
    can anyone help me with this error im getting? im trying to change this code from php to pdo and am having a problem with the delete code im getting this error Warning: Variable passed to each() is not an array or object in /home/a.php on line 37
    thanks.

    PHP Code:
    <?php
    require("db.php");
    $query "SELECT invoicenumber FROM hostingpackage";
    ?>
    <table width="400" border="0" cellspacing="1" cellpadding="0">
        <tr>
            <td>
                <form name="form1" method="post" action="">
                <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
                <tr>
                    <td bgcolor="#FFFFFF">&nbsp;</td>
                    <td colspan="4" bgcolor="#FFFFFF"></td>
                </tr>
                <tr>
                    <td align="center" bgcolor="#FFFFFF">#</td>
                    <td align="center" bgcolor="#FFFFFF"><strong>Invoice Number</strong></td>
                </tr>
                <?php $stmt $db->prepare($query);
      
    $result $stmt->execute($query_params);
      
    $result $stmt->setFetchMode(PDO::FETCH_NUM);
    while (
    $rows $stmt->fetch($result)) { ?>
                <tr>
                    <td align="center" bgcolor="#FFFFFF"><input name="need_delete[<? echo $rows['id']; ?>]" type="checkbox" id="checkbox[<? echo $rows['id']; ?>]" value="<? echo $rows['id']; ?>"></td>
                    <td bgcolor="#FFFFFF"><? echo htmlspecialchars($rows['invoicenumber']); ?></td>
                </tr>
                <?php ?>
                <tr>
                    <td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td>
                </tr>
                <?php
       
    if($_POST['delete']){
      
    $i 0;
      while(list(
    $key$val) = each($_POST['checkbox'])) {
        
    $sql "DELETE FROM $tbl_name WHERE id='$val'";
        
    mysql_query($sql);
        
    $i += mysql_affected_rows();
      }
      if(
    $i 0){
        echo 
    '<meta http-equiv="refresh" content="0;URL=a.php">';
      }
    }                
    ?>
                </table>
                </form>
            </td>
        </tr>
    </table>

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,537
    If I'm reading things correctly, I think you're using the wrong input element name:
    PHP Code:
    each($_POST['checkbox'])

    // ... should instead be:

    each($_POST['need_delete']) 
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles