TottoBennington Posted April 12, 2012 Share Posted April 12, 2012 Here´s the code ... this file is articles.php <?php if(!function_exists('get_articles1')){ function get_articles1() { //error is in this line $articles = array (); $query = mysql_query("SELECT * FROM articles "); while ($row = mysql_fetch_assoc($query)){ $articles[] = array ( 'article_id' => $row ['article_id'], 'article_title' => $row['article_title'], 'article_likes' => $row ['article_likes'], 'article_description' => $row['article_description'], 'article_date' => $row['article_date'], 'article_admin' => $row['article_admin'] ); } return $articles; } } ?> This is my index page code .. i call to the function here : <?php $articles = get_articles1(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/260817-cannot-redeclare-function-php-error/ Share on other sites More sharing options...
MMDE Posted April 12, 2012 Share Posted April 12, 2012 What makes you think you can call on the function if it's in another file? It's not like PHP goes through all your files looking for it. Or is this not the problem? Do you want to declare the function twice? Quote Link to comment https://forums.phpfreaks.com/topic/260817-cannot-redeclare-function-php-error/#findComment-1336748 Share on other sites More sharing options...
Jessica Posted April 12, 2012 Share Posted April 12, 2012 I'd recommend doing a find-all on your entire directory looking for that function name. It must be being included more than once. Checking if the function exists is not a great way to handle this, you should probably work on your include structure to make sure it's only included once. include_once helps. Quote Link to comment https://forums.phpfreaks.com/topic/260817-cannot-redeclare-function-php-error/#findComment-1336749 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.