sitesme Posted August 18, 2010 Share Posted August 18, 2010 Hi, After moving server my script started showing this error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/user/public_html/blog.php on line 107 Here is the code on line 107: if(mysql_num_rows($ExeqryComm)!=0){ Any help please? Thank you all Quote Link to comment https://forums.phpfreaks.com/topic/211072-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/ Share on other sites More sharing options...
ober Posted August 18, 2010 Share Posted August 18, 2010 Can you show us more of the code? Quote Link to comment https://forums.phpfreaks.com/topic/211072-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1100768 Share on other sites More sharing options...
sitesme Posted August 18, 2010 Author Share Posted August 18, 2010 Sure, here it is: $SelectqryComm="select * from ". COMMENT . " where commentid='$Menu' and varStatus='Active' order by CommDate limit $offset, $limit"; $ExeqryComm=mysql_query($SelectqryComm); $BlogCommentsdis.='<table cellpadding="0" cellspacing="0" border="0">'; $i =0; $BlogCommentsdis.=' <tr> <td> <form action="" method="post" name="commentfrm" onSubmit="return fn_comments();"><table width="79%" border="0" align="left" cellpadding="3" cellspacing="3" height="80px">'; if($statusemail=="suc") { $BlogCommentsdis.='<tr> <td colspan="2" align="center" class="informationbox" style="text-align:center">'.$varConfirmationOpiniao.'</td> </tr>'; } $BlogCommentsdis.='<tr> <td width="51%" align="right" style="text-align:right;" class="smalltxt">Nome <span class="error">*</span> </td> <td width="49%" align="left"><input type="text" name="varName" class="txt" size="50"/></td> </tr> <tr> <td align="right" style="text-align:right;" class="smalltxt">Email <span class="error">*</span></td> <td align="left"><input type="text" name="varEmail" class="txt" size="50"/></td></tr> <!-- <tr> <td align="right" style="text-align:right;" class="smalltxt">Data <span class="error">*</span></td> <td align="left"><input name="varData" type="text" class="txt"/></td> </tr>--> <tr> <td align="right" style="text-align:right;" class="smalltxt">Localidade <span class="error">*</span></td> <td align="left"><input name="varLocalidade" type="text" class="txt"/></td> </tr> <tr valign="top"> <td height="27" align="right" class="smalltxt">Comentário <span class="error">*</span></td> <td height="27" class="leftcontent"><textarea name="shortnews" cols="50" rows="6" class="inputbox1"></textarea></td> </tr> <tr valign="top"><td height="27" colspan="3" align="center"><input type="submit" name="post" id="post" value="Submeter" class="buttonsub"><input type="hidden" name="task" id="task" value="'.base64_encode($Menu).'"></td></tr> </table> </form> </td> </tr> <tr> <td> <table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">'; if(mysql_num_rows($ExeqryComm)!=0){ $BlogCommentsdis.='<tr> <td width="76%" class="pickheadcss">As opiniões</td> </tr>'; while($FetchqryComm=mysql_fetch_array($ExeqryComm)) { $i++; $CommDate_blog = dateformat($FetchqryComm['CommDate']); $Description_blog = $FetchqryComm['Description']; $bid = $FetchqryBlog['intblogid']; $varName_blog = $FetchqryComm['varName']; $varEmail_blog = $FetchqryComm['varEmail']; $BlogCommentsdis.='<tr> <td width="76%" class="picktext14">'.$varName_blog.'</td> </tr><tr> <td width="76%" class="new">'.$CommDate_blog.'</td> </tr> <tr> <td width="76%" class="new"> </td> </tr> <tr> <td>'.$Description_blog.'</td> </tr> <tr> <td style="border-bottom:1px solid #ffa2b5;"> </td> </tr>'; } $BlogCommentsdis.='<tr> <td><table width="65%" border="0" align="center" cellpadding="3" cellspacing="3"> <tr> <td width="97%" align="right">'; if($limit < $total) { if ($page == 1) { echo ""; } else { $BlogCommentsdis.="<a href=\"".$_SERVER['PHP_SELF']."?task=MTQ=view&sortby=".$SortList."&page=" . ($page - 1) . "\" class='linksnew'>Prev</a>"; } for ($i = 1; $i <= $pager->numPages; $i++) { $BlogCommentsdis.=" | "; if ($i == $pager->page) { $BlogCommentsdis.="<span class='Hint1'>"."$i"."</span>"; } else { $BlogCommentsdis.="<a href=\"".$_SERVER['PHP_SELF']."?task=MTQ=view&sortby=".$SortList."&page=$i\" class='linksnew'> $i</a>"."</font>"; } } if ($i > 1) { $BlogCommentsdis.=" | "; } if ($page == $pager->numPages) { $BlogCommentsdis.=""; } else { $BlogCommentsdis.="<a href=\"".$_SERVER['PHP_SELF']."?task=MTQ=view&sortby=".$SortList."&page=" . ($page + 1) . "\" class='linksnew'>Next</a>"; } } $BlogCommentsdis.='</td> <td width="3%" align="right"> </td> </tr> </table></td> Thanks Quote Link to comment https://forums.phpfreaks.com/topic/211072-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1100769 Share on other sites More sharing options...
PFMaBiSmAd Posted August 18, 2010 Share Posted August 18, 2010 If your code previously worked, the error (and if you searched for that error you would already know) means that your query failed due to an error either with the database server, your connection to the database server, or with your table/query. For debugging purposes (remove it when you are done), to find out why your query failed, you can echo mysql_error() on the next line after the line with your mysql_query() statement. Quote Link to comment https://forums.phpfreaks.com/topic/211072-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1100772 Share on other sites More sharing options...
sitesme Posted August 18, 2010 Author Share Posted August 18, 2010 The transfer was made between servers and it shouldn't be any problem on both versions. I believe it is a matter of configuration in PHP or MySQL. I remember a similar problem that was fixed with some sort of "hide errors" on PHP configuration or somewhat? Quote Link to comment https://forums.phpfreaks.com/topic/211072-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1100862 Share on other sites More sharing options...
TOA Posted August 18, 2010 Share Posted August 18, 2010 The transfer was made between servers and it shouldn't be any problem on both versions. I believe it is a matter of configuration in PHP or MySQL. I remember a similar problem that was fixed with some sort of "hide errors" on PHP configuration or somewhat? I would recommend fixing the problem rather than just turning off error reporting Quote Link to comment https://forums.phpfreaks.com/topic/211072-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1100865 Share on other sites More sharing options...
sitesme Posted August 18, 2010 Author Share Posted August 18, 2010 Fixing the problem is my first option as well... Any help please? Thanks to all. Quote Link to comment https://forums.phpfreaks.com/topic/211072-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1100866 Share on other sites More sharing options...
PFMaBiSmAd Posted August 18, 2010 Share Posted August 18, 2010 Someone already post how to determine why the query is failing. Quote Link to comment https://forums.phpfreaks.com/topic/211072-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1100869 Share on other sites More sharing options...
TOA Posted August 18, 2010 Share Posted August 18, 2010 And you're sure the transfer isn't the culprit? I usually see this error if the query failed and you don't realize it (I'm with PFMaBiSmAd...use mysql_error() ), you're using the wrong variable in the argument, or if the field type got switched in the db. Can you double check those things? Quote Link to comment https://forums.phpfreaks.com/topic/211072-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1100870 Share on other sites More sharing options...
sitesme Posted August 18, 2010 Author Share Posted August 18, 2010 As I don't want to damage the code, can you please tell me the exact line where I should add "echo mysql_error()"? Thank you Quote Link to comment https://forums.phpfreaks.com/topic/211072-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1100885 Share on other sites More sharing options...
TOA Posted August 18, 2010 Share Posted August 18, 2010 As I don't want to damage the code, can you please tell me the exact line where I should add "echo mysql_error()"? Thank you $ExeqryComm=mysql_query($SelectqryComm) or die (mysql_error()); It should be added to all queries during testing stages Quote Link to comment https://forums.phpfreaks.com/topic/211072-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1100891 Share on other sites More sharing options...
sitesme Posted August 18, 2010 Author Share Posted August 18, 2010 I got this error: 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 '-20, 20' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/211072-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1100894 Share on other sites More sharing options...
sitesme Posted August 18, 2010 Author Share Posted August 18, 2010 Just to make sure... I replaced $ExeqryComm=mysql_query($SelectqryComm); to $ExeqryComm=mysql_query($SelectqryComm) or die (mysql_error()); Am I supposed to try something else? Quote Link to comment https://forums.phpfreaks.com/topic/211072-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1100898 Share on other sites More sharing options...
PFMaBiSmAd Posted August 18, 2010 Share Posted August 18, 2010 Now that you know there is an SQL syntax error in the query, you would need to examine the actual query that is being formed in order to determine why a -20 is being put into it in order to fix it (it's likely in a pagination LIMIT clause...) Quote Link to comment https://forums.phpfreaks.com/topic/211072-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1100899 Share on other sites More sharing options...
sitesme Posted August 18, 2010 Author Share Posted August 18, 2010 Hi PFMaBiSmAd, Your help is highly appreciated but I have no clue how to proceed and fix this. I don't understand the -20 error you mentioned. Is this in the PHP or can it be in the MySQL? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/211072-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1100901 Share on other sites More sharing options...
TOA Posted August 18, 2010 Share Posted August 18, 2010 It's telling you it doesn't like the $offset and $limit variables, but since you only showed us a portion of your code, we can't tell what's going on before line 20, (like are they being populated correctly). Try wrapping them in single quotes and see what happens Quote Link to comment https://forums.phpfreaks.com/topic/211072-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1100902 Share on other sites More sharing options...
sitesme Posted August 18, 2010 Author Share Posted August 18, 2010 I've changed from: $SelectqryComm="select * from ". COMMENT . " where commentid='$Menu' and varStatus='Active' order by intid limit $offset, $limit"; to: $SelectqryComm="select * from ". COMMENT . " where commentid='$Menu' and varStatus='Active' order by intid limit '$offset', '$limit'"; but the result is the same. I removed the "limit $offset, $limit" part and the error is gone but then... I do not get pagination in the page... The full page code is here: // Display Event Details $Q_Check = "select * from ". COMMENT . " where commentid='$Menu' and varStatus='Active' order by CommDate"; $R_Check = mysql_query($Q_Check) or die(mysql_error()); $C_Check = mysql_num_rows($R_Check); $total = mysql_num_rows($R_Check); $page = $_GET['page']; $limit = $Fetch['intRows']; //$limit = 10; $pager = getPagerData($total, $limit, $page); $offset = $pager->offset; $limit = $pager->limit; $page = $pager->page; $SelectqryComm="select * from ". COMMENT . " where commentid='$Menu' and varStatus='Active' order by CommDate limit $offset, $limit"; $ExeqryComm=mysql_query($SelectqryComm); $BlogCommentsdis.='<table cellpadding="0" cellspacing="0" border="0">'; $i =0; $BlogCommentsdis.=' <tr> <td> <form action="" method="post" name="commentfrm" onSubmit="return fn_comments();"><table width="79%" border="0" align="left" cellpadding="3" cellspacing="3" height="80px">'; if($statusemail=="suc") { $BlogCommentsdis.='<tr> <td colspan="2" align="center" class="informationbox" style="text-align:center">'.$varConfirmationOpiniao.'</td> </tr>'; } $BlogCommentsdis.='<tr> <td width="51%" align="right" style="text-align:right;" class="smalltxt">Nome <span class="error">*</span> </td> <td width="49%" align="left"><input type="text" name="varName" class="txt" size="50"/></td> </tr> <tr> <td align="right" style="text-align:right;" class="smalltxt">Email <span class="error">*</span></td> <td align="left"><input type="text" name="varEmail" class="txt" size="50"/></td></tr> <!-- <tr> <td align="right" style="text-align:right;" class="smalltxt">Data <span class="error">*</span></td> <td align="left"><input name="varData" type="text" class="txt"/></td> </tr>--> <tr> <td align="right" style="text-align:right;" class="smalltxt">Localidade <span class="error">*</span></td> <td align="left"><input name="varLocalidade" type="text" class="txt"/></td> </tr> <tr valign="top"> <td height="27" align="right" class="smalltxt">Comentário <span class="error">*</span></td> <td height="27" class="leftcontent"><textarea name="shortnews" cols="50" rows="6" class="inputbox1"></textarea></td> </tr> <tr valign="top"><td height="27" colspan="3" align="center"><input type="submit" name="post" id="post" value="Submeter" class="buttonsub"><input type="hidden" name="task" id="task" value="'.base64_encode($Menu).'"></td></tr> </table> </form> </td> </tr> <tr> <td> <table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">'; if(mysql_num_rows($ExeqryComm)!=0){ $BlogCommentsdis.='<tr> <td width="76%" class="pickheadcss">As opiniões</td> </tr>'; while($FetchqryComm=mysql_fetch_array($ExeqryComm)) { $i++; $CommDate_blog = dateformat($FetchqryComm['CommDate']); $Description_blog = $FetchqryComm['Description']; $bid = $FetchqryBlog['intblogid']; $varName_blog = $FetchqryComm['varName']; $varEmail_blog = $FetchqryComm['varEmail']; $BlogCommentsdis.='<tr> <td width="76%" class="picktext14">'.$varName_blog.'</td> </tr><tr> <td width="76%" class="new">'.$CommDate_blog.'</td> </tr> <tr> <td width="76%" class="new"> </td> </tr> <tr> <td>'.$Description_blog.'</td> </tr> <tr> <td style="border-bottom:1px solid #ffa2b5;"> </td> </tr>'; } $BlogCommentsdis.='<tr> <td><table width="65%" border="0" align="center" cellpadding="3" cellspacing="3"> <tr> <td width="97%" align="right">'; if($limit < $total) { if ($page == 1) { echo ""; } else { $BlogCommentsdis.="<a href=\"".$_SERVER['PHP_SELF']."?task=MTQ=view&sortby=".$SortList."&page=" . ($page - 1) . "\" class='linksnew'>Prev</a>"; } for ($i = 1; $i <= $pager->numPages; $i++) { $BlogCommentsdis.=" | "; if ($i == $pager->page) { $BlogCommentsdis.="<span class='Hint1'>"."$i"."</span>"; } else { $BlogCommentsdis.="<a href=\"".$_SERVER['PHP_SELF']."?task=MTQ=view&sortby=".$SortList."&page=$i\" class='linksnew'> $i</a>"."</font>"; } } if ($i > 1) { $BlogCommentsdis.=" | "; } if ($page == $pager->numPages) { $BlogCommentsdis.=""; } else { $BlogCommentsdis.="<a href=\"".$_SERVER['PHP_SELF']."?task=MTQ=view&sortby=".$SortList."&page=" . ($page + 1) . "\" class='linksnew'>Next</a>"; } } $BlogCommentsdis.='</td> <td width="3%" align="right"> </td> </tr> </table></td> </tr>'; } $BlogCommentsdis.='</table> </td> </tr> <tr> <td> </td> </tr>'; $BlogCommentsdis.='</table>'; ?> Any help is appreciated. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/211072-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1100910 Share on other sites More sharing options...
TOA Posted August 18, 2010 Share Posted August 18, 2010 Ok, not surprised. Have you tried putting in the query directly into your admin to see if it works? Quote Link to comment https://forums.phpfreaks.com/topic/211072-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1100914 Share on other sites More sharing options...
MadTechie Posted August 18, 2010 Share Posted August 18, 2010 Your "$pager" class isn't giving you the correct results, so thats probably the part thats broken, you should fix that, a quick hack would be $offset = $pager->offset; $offset = ($offset < 0)?0:$offset; //<--add quick little hack Quote Link to comment https://forums.phpfreaks.com/topic/211072-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1100918 Share on other sites More sharing options...
sitesme Posted August 18, 2010 Author Share Posted August 18, 2010 Thanks to everyone. MadTechie, that fixed my problem. Many thanks for the great help of all Quote Link to comment https://forums.phpfreaks.com/topic/211072-warning-mysql_num_rows-supplied-argument-is-not-a-valid-mysql-result-resourc/#findComment-1100923 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.