Welcome to WebmasterWorld Guest from 50.17.79.100

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP script is being stopped by osCommerce?

search engine URLs,

     

BRoberson1657

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

4:30 pm on Jun 15, 2011 (gmt 0)

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



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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month