Page 1 of 1

Warning: mysql_num_rows() expects parameter 1

Posted: Thu Oct 29, 2009 11:40 am
by Naeem
When i add quote at the end of this link
example:http://localhost/articlemania/category.php?cid=3"
it's give me an error
here is :
"
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\articlemania\category.php on line 42"

here is my code:

Code: Select all

<?php 
include("inc/connection.php");
include_once("inc/functions.php");
$cat_id = $_GET['cid'];
$select_page_title = ("SELECT cat_name FROM category WHERE cat_id = '$cat_id'");
$querying_page_title = mysql_query($select_page_title);
$fetching_page_title = mysql_fetch_assoc($querying_page_title);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><?php echo "Article Mania - {$fetching_page_title['cat_name']}"; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="inc/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<table border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td valign="top"><?php include("inc/header.php"); ?> </td>
</tr>
</table>
<table border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="left" valign="top"><?php include("inc/left.php"); ?> </td>
<!--  Main Conent Area Start here -->
<td align="left" valign="top"><table width="506" border="0" align="center" cellpadding="0" cellspacing="0">
<tr> 
<td valign="top"><?php echo "------>&nbsp;&nbsp;{$fetching_page_title['cat_name']}"; ?><br /><img src="inc/images/main_content_area.gif" alt="main content" width="506" height="33"></td>
</tr>
<tr> 
<td class="mcbg"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr> 
<td width="1">&nbsp;</td>
<td><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<?php
if(intval($cat_id) <= 0 && is_string($cat_id)){
    common_error("Invalid category specified");
    exit();
    } else {
    $select_article_indivisual = ("SELECT * FROM article where cat_id = \"$cat_id\" ORDER BY article_id DESC");
    $querying_article_indivisual = mysql_query($select_article_indivisual);
    $select_article_indivisual_rows = mysql_num_rows($querying_article_indivisual);
    if($select_article_indivisual_rows <= 0){
    common_error("No article available at this time");
    exit();
    } else {
        while($retrieve_article_indivisual = mysql_fetch_assoc($querying_article_indivisual)){
echo "<tr> 
<td bgcolor=\"#E8E8E8\" class=\"style2\"><font size=\"2\" face=\"Arial, Verdana, Helvetica, sans-serif\"><a href=\"article.php?aid=$retrieve_article_indivisual[article_id]\" alt=\"$retrieve_article_indivisual[article_title]\"><b><u>$retrieve_article_indivisual[article_title]</u></b></a></font></td>
</tr>
<tr> 
<td><font face=\"Arial, Verdana, Helvetica, sans-serif\" size=\"2\"><br />".shortstring($retrieve_article_indivisual['article_text'])."<br /></font></td></tr>
<tr> 
<td><font size=\"1\">&nbsp;</font></td></tr>
<tr>
<td bgcolor=\"#E8E8E8\"><span class=\"style2\"><hr><font size=\"2\" face=\"Arial, Verdana, Helvetica, sans-serif\"><b>Posted Date:&nbsp;$retrieve_article_indivisual[article_date] | Category:&nbsp;<a href=\"category.php?cid=$retrieve_article_indivisual[cat_id]\" alt=\"$retrieve_article_indivisual[cat_name]\">".ucwords($retrieve_article_indivisual['cat_name'])."</a></b></font></span><br />
<hr>
</td>
</tr>";
            }
        }
    }
?>
<!-- Copyright start Here
<tr>
<td class="crbg"><div align="center"><font size="1">&copy; 2005 - <strong><a href="http://www.zymic.com"><font color="#208226">Free Templates</font></a> <font color="#00F43E"><a href="http://www.zymic.com">By 
<font color="#208226">Zymic.com</font></a></font></strong> - Content by your <strong>site name</strong> - 100% Valid HTML 4.01 Transitional!</font></div></td>
</tr>
 --> 
</table></td>
<!-- Main Content Area end here -->
</tr>
</table>
</body>
</html>

Re: Warning: mysql_num_rows() expects parameter 1

Posted: Thu Oct 29, 2009 1:43 pm
by requinix
Is that actually category.php? Because I don't see 39 lines there.

Re: Warning: mysql_num_rows() expects parameter 1

Posted: Thu Oct 29, 2009 10:58 pm
by Naeem
Bro Please check now i have posted the complete code

Re: Warning: mysql_num_rows() expects parameter 1

Posted: Thu Oct 29, 2009 11:59 pm
by requinix
Stick an

Code: Select all

or die(mysql_error())
after that one mysql_query and see what MySQL is complaining about.

Re: Warning: mysql_num_rows() expects parameter 1

Posted: Fri Oct 30, 2009 12:36 am
by Naeem
Thanks tasairis,
Now it say's
"
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\articlemania\category.php on line 42
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"1"" ORDER BY article_id DESC' at line 1"

Re: Warning: mysql_num_rows() expects parameter 1

Posted: Fri Oct 30, 2009 1:03 am
by requinix
Well, it sounds like you have an error in your SQL syntax. You should probably check that you're using the right syntax near the

Code: Select all

"1"" ORDER BY article_id DESC
part in the query.

Not sure what the query is? Print it out.

Re: Warning: mysql_num_rows() expects parameter 1

Posted: Fri Oct 30, 2009 1:20 am
by Naeem
Thanks for your quick support brother i have solved it just change this code
$cat_id = $_GET['cid'];
to
$cat_id = intval($_GET['cid']);