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

 

Link to comment
Share on other sites

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.

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.