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
Share on other sites

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?

Link to comment
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.

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.