Hello,

can anyone help me on this when i try to hit an invalid link to my site it gives me this :

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/nadia/public_html/showarticle.php on line 39

here's my showarticle.php

<?php
require_once ("includes/config.php");
require_once ("includes/functions.php");
$script_name = 'showarticle';

if (REWRITE_URLS == 1) {

    // split the path variables into something your can use
    $var_array = explode("/", $_SERVER['REQUEST_URI']);
        
    // get path to query db
    $depth_of_script_category = DEPTH_OF_SCRIPT + 1; 
    $depth_of_script_article = DEPTH_OF_SCRIPT + 2;    
    
    // get everything after the '_'
    $article_id = substr(strrchr($var_array[$depth_of_script_article], '_'), 1 );
    
} else {

    // mod rewrite is off 
    // trim data and query db
    $article_id = trim($_REQUEST['article']);

    
}


// lets query the db
$sql = "
    SELECT * 
    FROM pqdb_articles, pqdb_categories
    WHERE article_id = " . mysql_real_escape_string($article_id) . " 
    $query_ext
    AND category_id = article_cat
";
    
$result = mysql_query($sql);

if (mysql_num_rows($result) < 1) {
  
    $show_article = "Oops!  Something went wrong";  
              
} else {

    while ($article = mysql_fetch_array($result)) {
    
        // format category names (get rid of "Information ...")
        $take_out = array("& Information", "Information on", "Information");
        $category_desc = str_replace($take_out, "", $article['category_desc']);
    
        $category_name = $article['category_name'];
        $category_id = $article['category_id'];        
        $meta_key = $article['category_meta_key'] . ", " . $article['article_meta_key'];
        $meta_desc = $article['category_meta_desc'] . " " . $article['article_meta_desc'];
    
    
        $article_id = $article['article_id'];
        $article_title = $article['article_title'];
        $article_text = "<p>" . nicetrim(nl2br($article['article_text'])) . "</p>";
        $article_cat = $article['article_cat'];
        $article_meta_key = $article['article_meta_key'];
        $article_meta_desc = $article['article_meta_desc'];    
    }
    
    $show_article = "<h2 style=\"padding-bottom: 8px;\">$article_title</h2>\r$article_text";
    
}

// This is the <title> of your index page
$page_title = $article_title;

// These are your meta keywrds for the index page
$meta_key = $meta_key;

// This is your meta description for the index page
$meta_desc = $meta_desc;

require_once ("includes/head_meta_title.php");
?>


<div id="outer">
   <div id="innerwrap">
      <div id="centrecontent">
            <!--centre content goes here -->
          <!-- breadcrumb -->
            <div id="nav1">
                <ul><?php require_once ("includes/breadcrumb.php"); ?></ul>
            </div>
            <?php echo center_column_ad(); ?>
            <?php echo $show_article; ?>
            <?php echo center_rss(); ?>
            <?php if (CENTER_COLUMN_DYNAMIC_RSS == 1) {echo "<div style=\"margin-top: 20px; font-weight: bold;\">In The News:</div><hr />"; $q = str_replace("-","+",$category_name); include("includes/rss.php");} ?> 
      </div>
      
      <div id="left">
         <?php echo left_column(); ?>
            <?php echo left_rss(); ?>
      </div>
   </div>
    <!-- end innerwrap -->

   <div id="right">
        <?php echo right_column(); ?>
        <?php echo right_rss(); ?>
   </div>



<?php
require_once ("includes/header_footer.php");
?>

Please help me to solve this :(

Recommended Answers

All 6 Replies

Start with reading the sticky thread at the top of this forum. It will explain to you how you can determine what's causing this.

you got an error in your query
that's why mysql_query retuns FALSE and not a MySQL result resource.

$sql = "
SELECT *
FROM pqdb_articles, pqdb_categories
WHERE article_id = " . mysql_real_escape_string($article_id) . "
$query_ext
AND category_id = article_cat
";

what is $query_ext ?

Start with reading the sticky thread at the top of this forum. It will explain to you how you can determine what's causing this.

my file doesn't match what came to thread at all!!!!any suggestion!!

you got an error in your query
that's why mysql_query retuns FALSE and not a MySQL result resource.

$sql = "
SELECT *
FROM pqdb_articles, pqdb_categories
WHERE article_id = " . mysql_real_escape_string($article_id) . "
$query_ext
AND category_id = article_cat
";

what is $query_ext ?

actually i don't know it's a script that i downloaded it's very simple script with no error except this!!and the problem i'm a newbie in php and mysql :(

Change line 37 to this:

$result = mysql_query($sql) or die(mysql_error());

And show us the error message.

Change line 37 to this:

$result = mysql_query($sql) or die(mysql_error());

And show us the error message.

ohhhhh thank you man the problem is solved it was so easy like that!!!!thank you man i appreciate it :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.