Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: PHP
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
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 11-Sep-12 6:41am
Comments
Wes Aday at 11-Sep-12 12:44pm
   
The error means your query failed.
Zoltán Zörgő at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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...
  Permalink  
Comments
Hysen Ndregjoni at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 620
1 OriginalGriff 391
2 Maciej Los 210
3 PIEBALDconsult 180
4 Mehdi Gholam 145
0 Sergey Alexandrovich Kryukov 11,384
1 OriginalGriff 5,783
2 Maciej Los 5,684
3 CPallini 3,879
4 BillWoodruff 3,584


Advertise | Privacy | Mobile
Web01 | 2.8.141030.1 | Last Updated 11 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100