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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • linghuyuanye
    New Member
    • Feb 2009
    • 2

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

    I just learnt php yesterday. I have a problem whenever I submit the form on my webpage.It gives me Warning: Variable passed to each() is not an array or object. The array part in my form would be the group of checkbox. I set the name of the checkboxes to be "name=Contact_m e[]" ,which should make it an array(or is it not?) I've searched for similar topics, trying to figure out what's wrong,but I just can't figure it out. Can somebody please help me?


    Code:
    <?php
    
    $recipient = "me@hotmail.com";
    $subject = "Business Enquiry";
    
    //------------------------------------------------
    
    $q1_requirment = $_POST['requirment'];
    $q2_quantity = $_POST['quantity'];
    $q3_purchaseTime = $_POST['purchaseTime'];
    $q4_companyName = $_POST['companyName'];
    $q5_contactPerson = $_POST['contactPerson'];
    $q6_email = $_POST['email'];
    $q7_phoneNumber = $_POST['phoneNumber'];
    $q8_fax = $_POST['fax'];
    $q9_streetAddress = $_POST['streetAddress'];
    $q10_city = $_POST['city'];
    $q11_postalCode = $_POST['postalCode'];
    $q12_country = $_POST['country'];
    $q13_contactMe = $_POST['Contact_me'];
    
    //--------------------------------------------------
    
    while ((list($key,$val) = each($q13_contactMe)))
    {
    $q13_contactMe .= "[" . $val . "]";
    }
    $content = "Business Enquiry:\n
    ===========================================================\n
    	    Requirments:\n
                $q1_requirment\n
    ===========================================================\n
    	    Estimated quantity: $q2_quantity\n
    ===========================================================\n
    	    Purchase Time:      $q3_purchaseTime\n
    ===========================================================\n	    
    	    Contact person:     $q5_contactPerson\n
    ===========================================================\n
    	    Company name:       $q4_companyName\n
    ===========================================================\n
    	    Email:              $q6_email\n
    ===========================================================\n
    	    Phone Number:       $q7_phoneNumber\n
    ===========================================================\n
    	    Fax number:         $q8_fax\n
    ===========================================================\n
    	    Address:            $q10_streetAddress.".".$q10_city.".".$q11_postalCode.".".$q12_country\n
    ===========================================================\n
    	    Contact(prefered):  $q13_contactMe\n";
     	    
    $header = "From:$q4_companyName\n"."Reply-To:$q5_contactPerson";
    
    mail($recipient, $subject, $content, $header);
    exit;
    
    
    ?>
    <p align="center">Your enquiry has been sent.</p>
    <p align="center">Thank you for choosing FirstChoice Canada! </p>
    Last edited by Markus; Feb 14 '09, 12:00 AM. Reason: Fixed [code] tags.
  • xaxis
    New Member
    • Feb 2009
    • 15

    #2
    From: http://us2.php.net/each "each — Return the current key and value pair from an array and advance the array cursor" ...

    $q13_contactMe is not an array. Thus your problem, your are not passing an array as an argument to each().

    Comment

    • xaxis
      New Member
      • Feb 2009
      • 15

      #3
      Now that you have clarified your initial question, I believe what you want to do is assign each check box in your form its own unique name. Then you could do something like create an array containing all the names of your checkboxes which is used it to iterate through each checkbox to check if a value has been set and if so, push that value into another array:

      Code:
      $boxArr = array('box1','box2,'box3'); // array containing names of checkboxes
      $checkValues = array(); // array to store values of checked checkboxes
      
      foreach ($boxArr as $val) {
      $checkValues[] = (isset($_POST[$val])) ? $_POST[$val] : NULL;
      }
      All apologies for cutting this explanation a little short... It's been a good 34-35 awake and the old brain is going into auto shutdown mode.

      Comment

      • linghuyuanye
        New Member
        • Feb 2009
        • 2

        #4
        thankyou! I will try it out on next tuesday(since that's when I will have acess to the company's computer.)

        Comment

        Working...