Anyone know why do I get this error? [solved]

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
Maluendaster
Forum Contributor
Posts: 124
Joined: Fri Feb 25, 2005 1:14 pm

Anyone know why do I get this error? [solved]

Post by Maluendaster »

I just had to add an @ before mysql_fetch_array($result) )

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/pablo/public_html/wap/index.php on line 12

Here's the index.php

Code: Select all

<?php

	include 'config.php';
	
	$nu = time();


	$sql = ("SELECT * FROM wapupld_upload");
	$result = mysql_query($sql, $db);				
	$enable = 0;
						
	while($rs = mysql_fetch_array($result) ){ 
		$uptime = $rs["dato"];	
		$idnm = $rs["idnm"];					
		$filname = $rs["filname"];
			
		if(($nu-$uptime) >= $timeallowed) { // slet filen den er udløbet
			
				
				
				unlink("tmpfiles/$filname");
				$sql = ("DELETE FROM wapupld_upload WHERE idnm='$idnm'");
				mysql_query($sql, $db);
				
			
			
			}
					
	
	}


?>


<form enctype='multipart/form-data' action='<?php echo("$urltoindex");?>/uploadfile.php' method='post'> 
<table cellspacing='2' cellpadding='2' border='0'>



<tr>
      <td><p>file: </font></td>
    <td><input name='fil' type='file'></td>
</tr>
<tr>
      <td><p>file size limit: </font></td>
    <td><?php $r = $allowedsize/1024; echo("$r kb");?></td>
</tr>



<tr>
    <td><input name='submit' type='submit' value='Enviar Archivo'> </td>
      <td></td>
	  
</tr>
<input type='hidden' name='from' value='tree'>
</table>
</form>
<?php checklic($license);?>
Also, I get other error, but i don't want to show them and my site, how do i do that?

thanks
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Re: Anyone know why do I get this error? [solved]

Post by volka »

Maluendaster wrote:I just had to add an @ before mysql_fetch_array($result) )
That only supresses the error message. But still there's something wrong with your script. Try

Code: Select all

$sql = ("SELECT * FROM wapupld_upload");
$result = mysql_query($sql, $db) or die(mysql_error());
Sloth
Forum Newbie
Posts: 18
Joined: Thu Dec 07, 2006 7:29 pm

Post by Sloth »

uhm, I'd try counting the rows too

Code: Select all

$rows = mysql_num_rows($result);
Seems like he's getting an error while retrieve results so it might be a blank array
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Sloth wrote:Seems like he's getting an error while retrieve results so it might be a blank array
Yes and no.
mysql_query returns a mysql result resource for an SELECT statement, or FALSE if an error occured. "no records matched the criterias" is not an error, you will only get a result resource with no records attached to.
mysql_fetch_array() expects a result resource. If you pass a FALSE to it you will get the "supplied argument is not a valid MySQL result resource" warning. Same with mysql_num_rows().
Maluendaster
Forum Contributor
Posts: 124
Joined: Fri Feb 25, 2005 1:14 pm

Post by Maluendaster »

thanks for the replies, i'll try to do it again.
Post Reply