littlevisuals Posted July 28, 2009 Share Posted July 28, 2009 Hi everyone 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 Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted July 28, 2009 Share Posted July 28, 2009 It means that the argument value being passed to the foreach loop isn't an array Quote Link to comment Share on other sites More sharing options...
gevans Posted July 28, 2009 Share Posted July 28, 2009 Maybe your not passing an array into the foreach loop. Can you show the code around the foreach loop? Quote Link to comment Share on other sites More sharing options...
littlevisuals Posted July 28, 2009 Author Share Posted July 28, 2009 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) ); } ?> Quote Link to comment Share on other sites More sharing options...
gevans Posted July 28, 2009 Share Posted July 28, 2009 Where do you get $articleTag from? Quote Link to comment Share on other sites More sharing options...
littlevisuals Posted July 28, 2009 Author Share Posted July 28, 2009 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 Im going to modify it into my cms im making but thought id see if it works first. Quote Link to comment Share on other sites More sharing options...
gevans Posted July 28, 2009 Share Posted July 28, 2009 Untill you assign an array to $articleTag this will never work. Common sense is telling me that $article Tag should contain an array of tags however this fits into your system Quote Link to comment Share on other sites More sharing options...
littlevisuals Posted July 28, 2009 Author Share Posted July 28, 2009 Ok will do, thankyou so much Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.