homepage Welcome to WebmasterWorld Guest from 54.197.183.230
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
PHP script is being stopped by osCommerce?
search engine URLs,
BRoberson1657



 
Msg#: 4326107 posted 7:59 pm on Jun 14, 2011 (gmt 0)

Im getting the following error in a script..

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /Library/WebServer/Documents/QuarkWTP/HyperPublishing/hps_database_utility.php on line 182

Problem caused by osCommerce.
NOTE: (This problem manifested when I enabled "Use Search-Engine Safe URLs" and then goes away when I disable the "Use Search-Engine Safe URLs" feature in osCommerce. Unfortunately I need this feature to be activated because it facilitates the STS_Templates to work properly.)

Since the error message tells me what the problem is, I know where to start dealing with it but unfortunately I'm at a loss on how to fix it.

Below are the lines of code containing the referenced error
(line 182: $num_template_content = mysql_num_rows($result_template); )

------Code and surrounding lines-----------------

// Desc: retrieve template content for a publication
// Params: $template_id, $db
// Result: return $num_template_content
function get_template_content_count($template_id, $db){
$select_query = "SELECT * from hps_template_content WHERE template_id = " . $template_id;
$result_template = mysql_query($select_query, $db);
$num_template_content = mysql_num_rows($result_template);
//$template_content = mysql_fetch_assoc($result_template);
return $num_template_content;
-------------------------------------------------

The best I can tell is that it is a SELECT query that is stopping the script.... I am very new to PHP - can anyone explain this to me or point me in the right direction? I could really use a little guidance.

 

rocknbil

WebmasterWorld Senior Member rocknbil us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4326107 posted 4:30 pm on Jun 15, 2011 (gmt 0)

Welcome aboard BRoberson, what do you get when you add this?

$select_query = "SELECT * from hps_template_content WHERE template_id = " . $template_id;
echo $select_query;
exit;


Because there's no error trapping, I suspect $template_id is null/empty/undefined. In an unquoted select on an integer field, this will normally error (and should). So if you had error trapping in this function or even on the select ....

function get_template_content_count($template_id, $db){
if (! ($template_id > 0)) {
return "<p>Invalid template id: $template_id</p>";
}

$select_query = "SELECT * from hps_template_content WHERE template_id = " . $template_id;
$result_template = mysql_query($select_query, $db) or die("Cannot select template: " . mysql_error());
$num_template_content = mysql_num_rows($result_template);
//$template_content = mysql_fetch_assoc($result_template);
return $num_template_content;
}

It might tell you that. Also I don't know why this line is commented out:

//$template_content = mysql_fetch_assoc($result_template);

but I expect there's a reason.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved