September 24, 200719 yr Hi, I keep getting the error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/rodzi/domains/isyarikat.com/public_html/artikel.php on line 32 Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/rodzi/domains/isyarikat.com/public_html/artikel.php on line 33 The relevant code is: line 32 and 33 in artikel.php: $num=mysql_num_rows($result1); while($row=mysql_fetch_object($result1)) I did not get the error in my local machine (localhost), but i get that error when i load the page in the online server. Can Someone please help me?
September 24, 200719 yr I'd guess you're having trubble with your query on your server. Do you check the results of your query if it returns FALSE?
September 24, 200719 yr Author Thanks for your reply. But I dont understand what you mean when you said: Do you check the results of your query if it returns FALSE?. Here is the full code: <? if (isset($_GET['a_id'])) { $aa=$_GET['a_id']; $result1 = mysql_query("SELECT * FROM artikel_articles where a_id=$a_id"); $b=0; $num=mysql_num_rows($result1); while($row=mysql_fetch_object($result1)) {$b++; $a_id=$row->a_id; $a_title=$row->a_title; $a_pdf=$row->a_pdf; $a_date=strtotime($row->a_date); $a_link=$row->a_link; $a_desc=$row->a_desc; $a_ldesc=$row->a_ldesc; } ?> <p class="tajuk"><?=$a_title?></p> <p class="teks"> <?=$a_desc?> <br> <br> <? }?> The above code is to display full article content.
September 24, 200719 yr If your query is invalid, it'll return FALSE and not a result resource $result1 = mysql_query("SELECT * FROM artikel_articles where a_id=$a_id"); if ($result1 === false) { echo mysql_error(); die() } I'm wondering if you should have quotes around your $_id values in the query... like this: $result1 = mysql_query("SELECT * FROM artikel_articles where a_id='$a_id'"); And I see you put data from $_GET straight into the query $aa=$_GET['a_id']; $result1 = mysql_query("SELECT * FROM artikel_articles where a_id=$a_id"); which you should never ever do! Never trust the user. Escape all variables used in queries. Otherwise users can easily inject code to delete your entire db. $aa=mysql_real_escape_string($_GET['a_id']); $result1 = mysql_query("SELECT * FROM artikel_articles where a_id=$a_id");
September 24, 200719 yr you could also use: $result1 = mysql_query("SELECT * FROM artikel_articles WHERE a_id = ".$a_id.") or die( mysql_error() );
September 24, 200719 yr $result1 = mysql_query("SELECT * FROM artikel_articles WHERE a_id = ".$a_id) or die( mysql_error() ); You had an open quote there you could also use: $result1 = mysql_query("SELECT * FROM artikel_articles WHERE a_id = ".$a_id.") or die( mysql_error() );
September 24, 200719 yr lol sorry... my text editor usually helps me out by showing me the matching pair (eg shows start when i am next to the end or vice versa). Good spot though.
September 25, 200719 yr Author Thanks a lot guys for your help. A few minutes ago I implement one of your recommendations as in the following code. Let me put it in full: <? include("connection.php");?> <HTML> <HEAD> <TITLE>iSyarikat.com | Jendela Syarikat | Artikel</TITLE> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <LINK href="gaya.css" type=text/css rel=stylesheet> </HEAD> <BODY BGCOLOR=#FFFFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0> <div align="center"> <TABLE WIDTH=720 BORDER=0 CELLPADDING=0 CELLSPACING=0> <TR> <TD COLSPAN=5> <IMG SRC="imej/in_01.gif" WIDTH=720 HEIGHT=20 ALT=""></TD> </TR> <TR> <TD COLSPAN=7 ALIGN=left VALIGN=top> <map name="PetaMenu"> <area href="index.php" shape="rect" coords="42, 0, 155, 42"> </map> <IMG SRC="imej/atas2.gif" WIDTH=720 HEIGHT=44 BORDER="0" ALT="Kembali ke Laman Utama" usemap="#PetaMenu"></TD> </TR> <TR> <TD ALIGN=left VALIGN=top background="imej/in_03.gif" WIDTH=15></TD> <TD ALIGN=left VALIGN=top background="imej/in_04.gif" WIDTH=183></TD> <TD ALIGN=left VALIGN=top background="imej/in_05.gif" WIDTH=20></TD> <TD ALIGN=left VALIGN=top background="imej/in_06.gif" WIDTH=487><div align="center"><table width=90%><tr><td><img src=imej/pojok.gif></td></tr><tr><td height=10></td></tr> <tr><td class=teks><!--Kandungan artikel di sini---><? if (isset($_GET['a_id'])) { //$aa=$_GET['a_id']; //$result1 = mysql_query("SELECT * FROM artikel_articles where a_id=$a_id"); $aa=mysql_real_escape_string($_GET['a_id']); $result1 = mysql_query("SELECT * FROM artikel_articles WHERE a_id = ".$a_id.") or die( mysql_error() ); $b=0; $num=mysql_num_rows($result1); while($row=mysql_fetch_object($result1)) {$b++; $a_id=$row->a_id; $a_title=$row->a_title; $a_pdf=$row->a_pdf; $a_date=strtotime($row->a_date); $a_link=$row->a_link; $a_desc=$row->a_desc; $a_ldesc=$row->a_ldesc; } ?> <p class="tajuk"><?=$a_title?></p> <p class="teks"> <?=$a_desc?> <br> <br> <? }?> </p></td></tr></table></div></TD> <TD ALIGN=left VALIGN=top background="imej/in_07.gif" WIDTH=15></TD> </TR> <TR> <TD COLSPAN=5 ALIGN=left VALIGN=top> <IMG SRC="imej/in_08.gif" WIDTH=720 HEIGHT=25 ALT=""></TD> </TR> </TABLE> </div> </BODY> </HTML> And now I get the following error: Parse error: syntax error, unexpected T_INC, expecting '}' in /home/rodzi/domains/isyarikat.com/public_html/artikel.php on line 36 Please help me again. Thanks.
September 25, 200719 yr count your { and compare it to your count of } if they don't match, look more closely
September 26, 200719 yr Author count your { and compare it to your count of } if they don't match, look more closely I have counted several times, there are on '{' and one '}'. But at the bottom of the code there are one code which contain the following: <!--<? }?>--> AND NOW I HAVE IMPLEMENTED YOUR RECOMMENDATION. THE NEW CODE NOW IS AS BELOW: <? if (isset($_GET['a_id'])) { $aa=mysql_real_escape_string($_GET['a_id']); $result1 = mysql_query("SELECT * FROM artikel WHERE a_id ='$a_id'") or die( mysql_error() ); $b=0; $num=mysql_num_rows($result1); while($row=mysql_fetch_object($result1)) {$b++; $a_id=$row->a_id; $a_title=$row->a_title; $a_pdf=$row->a_pdf; $a_date=strtotime($row->a_date); $a_link=$row->a_link; $a_desc=$row->a_desc; $a_ldesc=$row->a_ldesc; } ?> NOW I GET A BLANK PAGE. Please help me again. Thanks.
September 26, 200719 yr Why is there <!--<? }?>--> Are you trying to comment it out? Like Thomas Said, make sure you add another }; at the end.
September 28, 200719 yr Author Why is there <!--<? }?>--> Are you trying to comment it out? Like Thomas Said, make sure you add another }; at the end. Hi everyone, Like what Thomas and BenG reccommended, I apply it now. Here is the code: <? if (isset($_GET['a_id'])) { $aa=mysql_real_escape_string($_GET['a_id']); $result1 = mysql_query("SELECT * FROM articles WHERE a_id ='$a_id'") or die( mysql_error() ); $b=0; $num=mysql_num_rows($result1); while($row=mysql_fetch_object($result1)) {$b++; $a_id=$row->a_id; $a_title=$row->a_title; $a_pdf=$row->a_pdf; $a_date=strtotime($row->a_date); $a_link=$row->a_link; $a_desc=$row->a_desc; $a_ldesc=$row->a_ldesc; } }; ?> BUT STILL I got the blank page! What really confused me is that it's working at my local server (NOT WORKING only at online server. Both servers has the same version of MySQL and PHP and Apache.
September 28, 200719 yr Author Hi everyone, Like what Thomas and BenG reccommended, I apply it now. Here is the code: <? if (isset($_GET['a_id'])) { $aa=mysql_real_escape_string($_GET['a_id']); $result1 = mysql_query("SELECT * FROM articles WHERE a_id ='$a_id'") or die( mysql_error() ); $b=0; $num=mysql_num_rows($result1); while($row=mysql_fetch_object($result1)) {$b++; $a_id=$row->a_id; $a_title=$row->a_title; $a_pdf=$row->a_pdf; $a_date=strtotime($row->a_date); $a_link=$row->a_link; $a_desc=$row->a_desc; $a_ldesc=$row->a_ldesc; } }; ?> BUT STILL I got the blank page! What really confused me is that it's working at my local server (NOT WORKING only at online server. Both servers has the same version of MySQL and PHP and Apache. Hi everyone, I really need help to solve the problem. Please download the entire script for your reference. Thanks. artnews.zip
September 28, 200719 yr Hi everyone, I really need help to solve the problem. Please download the entire script for your reference. Thanks. Check your MSQL connection details for your server and make sure they are the same as the ones you're including in your PHP. Here's the thing. A PHP script that is working in one place won't just fail when transferred to another. There has to be a reason for it and often it's not the script. It'll be a miss typed password or not changing 'localhost' to the correct IP address (we've all done it). Also, check whether your server is running in 'safe mode' and if so, set up your local server to do the same. You'll be amazed at how many problems you'll solve if you develop in the same environment as it will eventually be deployed. I've not had a chance to check the code yet, it will have to wait until I am at work. Does the ZIP file contain a dump of your database as well and if not could you post that too? It would be a help because I could then get it running locally myself and see what's happening.
September 28, 200719 yr Author Check your MSQL connection details for your server and make sure they are the same as the ones you're including in your PHP. Here's the thing. A PHP script that is working in one place won't just fail when transferred to another. There has to be a reason for it and often it's not the script. It'll be a miss typed password or not changing 'localhost' to the correct IP address (we've all done it). Also, check whether your server is running in 'safe mode' and if so, set up your local server to do the same. You'll be amazed at how many problems you'll solve if you develop in the same environment as it will eventually be deployed. I've not had a chance to check the code yet, it will have to wait until I am at work. Does the ZIP file contain a dump of your database as well and if not could you post that too? It would be a help because I could then get it running locally myself and see what's happening. Thanks for ur advice, The connection is ok. 100% sure. The other pages (I mean the listing pages) is working except the article content pages. I have included the dumping data in the zip files.
September 28, 200719 yr have you checked that none of the mysql function doesn't return a value that indicate failure? if any of them do, make sure you echo out the mysql_error()
September 28, 200719 yr Well it seams to work perfectly for me. I say seams to because I can't understand the language but appart form that, the website is coming up all right. Tell me, is http://www.mellorweb.co.uk/testing/ what you're expecting to see?
September 29, 200719 yr Author have you checked that none of the mysql function doesn't return a value that indicate failure? if any of them do, make sure you echo out the mysql_error() Hi, Thank you for your time and initiative to try to published the scripts. I have seen the site. BUT it's totally not working. I think you don't even add the database, cuz its looks like there are no data at all.
September 29, 200719 yr Author Well it seams to work perfectly for me. I say seams to because I can't understand the language but appart form that, the website is coming up all right. Tell me, is http://www.mellorweb.co.uk/testing/ what you're expecting to see? Hi, Thank you for your time and initiative to try to published the scripts. I have seen the site. BUT it's totally not working. I think you don't even add the database, cuz its looks like there are no data at all. Please have a look at the english version here: www.rodzi.net/i I upload again the new script (in full). To enter the admin you must go to the "editor" folder and login as rodzi:rodzi61 Thanks. i.zip
October 3, 200719 yr Well I uploaded the script that you sent and it is connected with the database (same link as before). The site still looks rather scarce though.
Create an account or sign in to comment