SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Warning: Invalid argument supplied for foreach()

  1. #1
    SitePoint Addict
    Join Date
    Mar 2011
    Location
    Manchester, UK
    Posts
    217
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Warning: Invalid argument supplied for foreach()

    Hi Guys,

    I have a script that keeps giving me an error:

    PHP Code:
    WarningInvalid argument supplied for foreach() in /home/loud/public_html/coreg/worldvision.php on line 62 
    On that line it is the following:

    PHP Code:
    foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
    rtrim($fields_string,'&'); 
    Can anyone help me here please as my variables are not being replaced with the data within the variables while this error is happening.

    Any help would be great please.

    Thanks
    You're Help Does Not Go Unnoticed, I have So Far Donated £10 GBP
    To Cancer Research UK As A Thank You To All The SitePoint
    Members That Have Helped Me In The PHP Forum Thank You!

  2. #2
    From Italy with love bronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    8,603
    Mentioned
    76 Post(s)
    Tagged
    4 Thread(s)
    foreach expects an array to loop through, and apparently $fields is not an array.
    Do a print_r($fields); before the loop to check its content.

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,849
    Mentioned
    16 Post(s)
    Tagged
    1 Thread(s)
    When you sort out why your array is not turning up, and you want to turn it into a query string, then take a look at the examples shown for http_build_query

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
  •