Jump to content

Boolean error calling external mysql_query?


UrbanDweller

Recommended Posts

Hey,

 

I found some code online that references a bunch of sql commands in there own functions that can be called from a require_once(), All the ones I have tried work expect mysql_query when its called it returns this error:

 

Warning: mysql_result() expects parameter 1 to be resource, boolean given in

 

But once i paste the mysql_query into the main script it works fines. code below is mine and the online script.

 

 

Webcode:

$sql = "SELECT cat_id, cat_parent_id, cat_name, cat_description, cat_image
        FROM tbl_category
        WHERE cat_parent_id = $catId
        ORDER BY cat_name";
/* 
Don't know what getPagingQuery does and couldnt find any reference to it so i removed it and replaced with simple query in my own code
*/
$result     = dbQuery(getPagingQuery($sql, $rowsPerPage)); 

 

My Code:

$sql = "SELECT cat_id, cat_parent_id, cat_name, cat_description, cat_image
        FROM tbl_category
        WHERE cat_parent_id = $catId
        ORDER BY cat_name";
$result     = dbQuery($sql); 

 

Include file:

$dbHost = "localhost"; //SQL Server
$dbUser = "root";	// Database username
$dbPass = "";	// Database password	
$dbName = "lh_shop"; // Database name

$sqlCon = mysql_connect($dbHost, $dbUser, $dbPass) or die ('MYSQL connection Failed. ' . mysql_error());	

mysql_select_db($dbName) or die('Cannot select database. ' . mysql_error());

// Database query functions
function dbQuery($sql)
{
   return mysql_query($sql) or die('Query failed. ' . mysql_error());
}

 

Thanks, I really hope someone has had this issue :P

 

But why is it that if i call the query not from the include but inside the main file the same code works.

 

I'm simply relating to you what the error message indicates.  You didn't provide the code that actually calls the error.  If this is code you didn't write yourself, as it seems you indicated in your original message, you'll have to learn enough about it to actually debug the problem.

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.