Jump to content

[SOLVED] Warning: Invalid argument supplied for foreach() ?


littlevisuals

Recommended Posts

Hi everyone  :D

 

Trying to add tags to a script so i've found a script online. However every time I run the script I get the error

 

Warning: Invalid argument supplied for foreach() in /Library/WebServer/Documents/tags.php on line 2

 

Can anybody tell me what this means?

 

Im using PHP Version 5.2.5, MySQL 5.1.35 via socket

Link to comment
Share on other sites

Sure, here is the code I have

 

<?php
      foreach ( $articleTags as $tag ) {
   
       
   
          $resultID = @mysql_query("SELECT tag_id FROM articles_tags WHERE tag_name='$tag'") or
   
              outputMessage( "SELECT FROM articles_tags failed: " . @mysql_error($linkID) );
   
          if ( $row = mysql_fetch_array($resultID, MYSQL_ASSOC) ) {
   
       
   
              $tagID = $row['tag_id'];
   
              @mysql_query("UPDATE articles_tags SET num_articles=num_articles+1 WHERE tag_id=$tagID") or
  
                  outputMessage( "UPDATE articles_tags failed: " . @mysql_error($linkID) );
  
       
  
          } else {
  
       
  
            @mysql_query("INSERT INTO articles_tags(tag_name) VALUES ('$tag')") or
  
                  outputMessage( "INSERT INTO articles_tags failed: " . @mysql_error($linkID) );
  
              $tagID = @mysql_insert_id() or outputMessage( "mysql_insert_id() failed: " . @mysql_error($linkID) );
  
          }
  
       
  
          @mysql_query("INSERT INTO articles_tagged (tag_id, article_id) VALUES ($tagID, $articleID)") or
  
              outputMessage( "INSERT INTO articles_tagged failed: " . @mysql_error($linkID) );
  
      }
  ?>

Link to comment
Share on other sites

I followed this tutorial online

 

http://www.itnewb.com/v/Comprehensive-Guide-to-PHP-MySQL-Tag-Clouds-Includes-Demo/page4

 

I couldn't understand where $articlestags even fits into it  :confused:

 

Im going to modify it into my cms im making but thought id see if it works first.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.