Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\Program Files\xampp\htdocs\ZA_Kamez\include.php on line 21

What does this error mean??

PHP
<?php
include 'blogpost.php';

$connection = mysql_connect('localhost', 'login_h', '1234') or die ("<p class='error'>Sorry, we were unable to connect to the database server.</p>");
$database = "articles";
mysql_select_db($database, $connection) or die ("<p class='error'>Sorry, we were unable to connect to the database.</p>");

function GetBlogPosts($inId=null, $inTagId =null)
{
	$query = null;
	if (!empty($inId))
	{
		$query = mysql_query("SELECT * FROM blog_posts WHERE id = " . $inId . " ORDER BY id DESC"); 
	}
	else
	{
		$query = mysql_query("SELECT * FROM blog_posts ORDER BY id DESC");
	}
	
	$postArray = array();
	while ($row = mysql_fetch_assoc($query))
	{
		$myPost = new BlogPost($row["id"], $row['title'], $row['post'], $row['postfull'], $row["author_id"], $row['date_up']);
		array_push($postArray, $myPost);
	}
	return $postArray;
}
?>
Posted
Comments
[no name] 11-Sep-12 12:44pm    
The error means your query failed.
Zoltán Zörgő 11-Sep-12 13:09pm    
And this is the "ZA_Kamez\include.php" script? The row number seems not to match. But be sure to find the code line mentioned in the error message and add a var_dump(???); before it - where ??? is the variable you passed to the function.

1 solution

It means, mysql_query() function is failing and returning a boolean(False). Make sure you have rights to access blog_posts table or check if it exists or not.
You can also test your query on phpmyadmin...
 
Share this answer
 
Comments
Hysen Ndregjoni 11-Sep-12 14:14pm    
thanks I found the problem , the table was called posts and I've used "blog_posts"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900