Warning: mysql_fetch_array(): supplied argument ERROR help?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

Warning: mysql_fetch_array(): supplied argument ERROR help?

Post by robster »

Hi all,

I have a strange problem pulling info from my database.
I use the code below and on my home servers I've used (previously windows, and now OS X) it works fine, but on my hosted (red hat) server I get this error message:


Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /thisisafakepath/filename.php on line 57


Code: Select all

$connection = mysql_connect($dbhost, $dbusername, $dbpassword);
Last edited by robster on Fri Aug 15, 2003 4:16 am, edited 1 time in total.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

show us th wholw script. it'll be easier to see what is happening, because from the partial script you have given us, it looks like you have actually connected to the database.

mark
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

Post by robster »

Here it is, edited down to not show paths etc... I hope nobody minds...

Code: Select all

<?
include("header.php");
require("config.php");
?>





<!--Content left and right colums-->
<link href="v5.css" rel="stylesheet" type="text/css">

<table width="800" border="0" cellpadding="0" cellspacing="0"  class="td1">
  <tr>


    <!--LEft Column-->
    <td width="216" align="center" valign="top"  class="cell">

	<br>

	<!--soundfile sidebar-->
	<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
	<? $boxtoptext  ='Side info box title goes here';
	   include("box_top.php");  ?>

side info box text goes here, please note that box_top.php has the opening <td> required for this, so don't stress.  

		  </td>
   </tr>
   </table>
   <!--END soundfile sidebar-->

   <br>
      <!--Amazon box-->
		<?
		include("amazon_box.php");
		?>	  
      <!--End Amazon box-->
    </td>
   <!--End LEft Colums-->



 <!--RIght Column-->
    <td width="584" align="center" valign="top"  class="cell">

	<br>

	<!--soundfile column-->
<?
	$content = mysql_db_query($dbname, "SELECT * FROM current_round ORDER BY id DESC");
	$Xcontent = mysql_fetch_array($content);	

	$filename = $Xcontent["filename"];
	$monthname = $Xcontent["monthname"];
	$year = $Xcontent["year"];
	$month = $Xcontent["month"];
	$day = $Xcontent["day"];	
	$length = $Xcontent["length"];
	$filmlink = $Xcontent["filmlink"];
	$transcript = $Xcontent["transcript"];		
	$length = $Xcontent["length"];	
	$filesize = $Xcontent["filesize"];	
?>	
	
	<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr>
     <td width="100%" align="left" valign="top"  class="td2">
	 <?
		print "$monthname $year archived sound file...";
	 ?>
	  </td>
	</tr>
	<tr>
	      <td width="80%" align="left" valign="top"  class="td1">
		  <?
		  	print "<b>Sound File:</b> <a href="/archives/$year/$month/$filename">$filename</a><br>";
			print "<b>File Size:</b> $filesize Kb<br>";
			print "<b>Length of clip:</b> $length seconds<br>";
			print "<b>Film that clip is taken from:</b> <a href="$filmlink" target="new">Click to see film</a>";
		  ?>
		  </td>
   </tr>
   </table>
   <!--END soundfile right column-->

<br>

	<!--transcript column-->
	<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr>
     <td width="100%" align="left" valign="top"  class="td2">
		Transcript...
	  </td>
	</tr>
	<tr>
	      <td width="80%" align="left" valign="top"  class="td1">
		  <?
			print "$transcript";
		  ?>
		  </td>
   </tr>
   </table>
   <!--END transcript right column-->

<br>


	<!--date due column-->
	<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr>
     <td width="100%" align="left" valign="top"  class="td2">

		When was the deadline for this archived sound file?

	  </td>
	</tr>
	<tr>
	      <td width="80%" align="left" valign="top"  class="td1">
 			This entry was for 
			<?
			print "$monthname";
			print " $year";
			?>
		  </td>
   </tr>
   </table>
   <!--END date due right column-->

	</td>
	<!--End RIght Colums-->



  </tr>
</table>
<!--End Left and Right Columns-->

<!--Footer-->
<?
include("footer.php");
?>
<!--End Footer-->
What's interesting with this, is it's not even showing the database contents now, but on my work machine (windows box) I've tried it and it works a treat. I'm so confused now.

Thanks again, I hope the whole script helps. It's probably a bit messy for you pros, but I am a learner (and loving it!) :)

Rob
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

just had a quick look so maybe I missed it, but where do u connect to the mysql database?
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

Post by robster »

oh... how did I miss that?!?! :)

Well, I added it anyway, and yes, the data then showed up (on my home test server) but I still get this error when on my server:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /fakepath/filename.php on line 60


Does anyone have any idea on what's causing this?!

So strange.

Thanks again :)

Rob
User avatar
Wayne
Forum Contributor
Posts: 339
Joined: Wed Jun 05, 2002 10:59 am

Post by Wayne »

are you doing any validation on your mysql_connect or mysql_db_query statements, because that is what the error is associated with, are the password, usernames, dbname and ip address all correct?!?

what is on is line 60 now? (or whatever line number is in the error message)
tylerdurden
Forum Commoner
Posts: 66
Joined: Mon Jul 28, 2003 11:52 am
Location: Austria

Post by tylerdurden »

What happens when you enter "SELECT * FROM current_round ORDER BY id DESC" in the MySQL Command Line Client or in a tool like PHPMyAdmin? I've found the most stupid errors this way, like typos in the table name and such.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Firstly, you should not be using mysql_db_query() as it is a deprecated function which the manual explicitely tells you not to use. Instead you should be using mysql_select_db() and mysql_query(). Add a bit of error handling to your code and see what you get:

Code: Select all

@mysql_select_db($dbname) or die(mysql_error());
$sql = "SELECT * FROM current_round ORDER BY id DESC";
$content = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');
I assume you are connecting to MySQL in one of your included files - if you're not then that'll be the problem.

Mac
Stoneguard
Forum Contributor
Posts: 101
Joined: Wed Aug 13, 2003 9:02 pm
Location: USA

Post by Stoneguard »

Actually, if the code works on your system and not the hosting system, I would suspect that the userid does not have the select privileges on the database table on the hosting box.
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

Post by robster »

Thanks for the reminder on the db_query redundancy Twigletmac.
ALL of my files have the old style. I'm a bit worried, if I leave them (due to the sheer time it will take to change them all) will this feature ever be... swtiched off so to speak? I sure hope not.


Also, thanks for the suggestion on the server side stuff Stoneguard. I'll talk to the admin on the server about that. Very helpful staff at netprohosting. They should give me some quick response...

Thanks all! :)

Rob
Post Reply