I have a site with 300 articles stored in a mySQL database with the URL format of www.site.com/article1.html.

Most invalid URLs redirect succesfully to the main site. For example, www.site.com/article301 redirects to www.site.com, which is what I want.

But www.site.com/article301.html does not redirect anywhere. Instead it loads a blank article template and the following error at the top of the page:

```
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home//public_html/site.com/functions.php on line 26

```

Line 26 and down reads

```
        if(mysql_num_rows($result)>0) {
        $row=mysql_fetch_array($result);
        if(ENABLE_REWRITE == 1) $path=' &raquo; <a href="'.DOC_ROOT.'/'.$row['nameurl'].'/page_1/">'.$row['name'].'</a>'.$path;
        if(ENABLE_REWRITE == 0) $path=' &raquo; <a href="index.php?page=1&category='.$id.'">'.$row['name'].'</a>'.$path;
        if($row['parent']==0) $f=1;
        else $id=$row['parent'];
    } else {
        return ' - ';
    }
}
return $path;
}

```

Any ideas how to fix this?

Here's the full code, as requested by King Skippus

```
<?php
/*function get_folders_path($id) {
    $f=0;
    $path='';
    while($f==0)
    {
        $result=mysql_query("SELECT name, parent FROM categories WHERE id=$id");
        if(mysql_num_rows($result)>0) {
            $row=mysql_fetch_array($result);
            $path=' &raquo; '.$row['name'].$path;
            if($row['parent']==0) $f=1;
            else $id=$row['parent'];
        } else {
            return ' - ';
        }
    }
    return $path;
}*/

function get_folders_path($id) {
    $f=0;
    $path='';
    while($f==0)
    {
        $result=mysql_query("SELECT * FROM categories WHERE id=$id");
        if($result !== FALSE && mysql_num_rows($result)>0) {
            $row=mysql_fetch_array($result);
            if(ENABLE_REWRITE == 1) $path=' &raquo; <a       href="'.DOC_ROOT.'/'.$row['nameurl'].'/page_1/">'.$row['name'].'</a>'.$path;
            if(ENABLE_REWRITE == 0) $path=' &raquo; <a href="index.php?page=1&category='.$id.'">'.$row['name'].'</a>'.$path;
            if($row['parent']==0) $f=1;
            else $id=$row['parent'];
        } else {
            return ' - ';
        }
    }
    return $path;
}

function get_categories_tree($id) {
    static $categs = array ();
    static $level=0;
    $level++;

    $result=mysql_query("SELECT * FROM categories WHERE parent=$id");

    while($row=mysql_fetch_array($result)) {
        $categs[$row['id']][0] = $row['id'];
        $categs[$row['id']][1] = '/'.$row['nameurl'];
        $categs[$row['id']][2] = str_repeat('&nbsp;&nbsp;', $level-1);
        $categs[$row['id']][3] = $row['name'];
        get_categories_tree($row['id']);
    }
    $level--; 
    return $categs;
}

function get_cats($id) {
    $categs = array ();
    $result=mysql_query("SELECT * FROM categories WHERE parent=$id");

    while($row=mysql_fetch_array($result)) {
        $categs[$row['id']][0] = $row['id'];
        $categs[$row['id']][1] = '/'.$row['nameurl'];
//      $categs[$row['id']][2] = str_repeat('&nbsp;&nbsp;', $level-1);
        $categs[$row['id']][3] = $row['name'];
    }
    return $categs;
}

/*function login() {
    if (!isset($_SERVER['PHP_AUTH_USER'])) {
       header('WWW-Authenticate: Basic realm="My Realm"');
       header('HTTP/1.0 401 Unauthorized');
       return false;
    } else {
        $result=mysql_query("SELECT * FROM users WHERE login='{$_SERVER['PHP_AUTH_USER']}' AND password='{$_SERVER['PHP_AUTH_PW']}'");
        if(mysql_num_rows($result)>0) return true;
        else {
            header('WWW-Authenticate: Basic realm="My Realm"');
            header('HTTP/1.0 401 Unauthorized');
            return false;
        }
    }
}*/

function login() {
    if (!isset($_SESSION['AUTH_USER']) || !isset($_SESSION['AUTH_PASS'])) return false;
    else {
        $result=mysql_query("SELECT * FROM users WHERE     login='{$_SESSION['AUTH_USER']}' AND password='{$_SESSION['AUTH_PASS']}'");
        if(mysql_num_rows($result)>0) return true;
        else return false;
    }
}

function get_categories($id) {
    static $categs = array ("0" => "[Top]");
    static $level=0;
    $level++;

    $result=mysql_query("SELECT * FROM categories WHERE parent=$id");

    while($row=mysql_fetch_array($result)) {
        $categs[$row['id']] = str_repeat('|&nbsp;&nbsp;&nbsp;', $level-1).'|___'.$row['name'];
        get_categories($row['id']);
    }
    $level--; 
    return $categs;
}

function get_parent_name($id) {
    if($id!=0) {
        $result=mysql_query("SELECT name FROM categories WHERE id=$id");
        if(mysql_num_rows($result)>0) {
            $row=mysql_fetch_array($result);
            return $row['name'];
        }
        else return '-';
    }
    else return 'Top';
}
function getcatname($id, $table)
{
        $r=mysql_query("SELECT title FROM $table WHERE id='$id'");
        if(mysql_num_rows($r)>0) {
            $row=mysql_fetch_array($r);
            return $row['title'];
        }
    else
        return "-";
}
?>

```