Jump to content

Cannot redeclare function (php error)


TottoBennington

Recommended Posts

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();
			?>

Link to comment
https://forums.phpfreaks.com/topic/260817-cannot-redeclare-function-php-error/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.