Hi guys,

I have a little code below that seems to keep returning the errors:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/www/site.com/pics.php on line 70

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/www/site.com/pics.php on line 84.

When I remove the WHERE statement (highlighted in bold below) it all works and the tables are set up correctly. Whats going on and How do I fix it?

Thanks.

<?php
require("databaseconnect.php");

mysql_select_db($dbase, $connect);








[B]$results = mysql_query("SELECT * FROM `pics` WHERE username='".$username."' LIMIT 1") or die(mysql_error());[/B]

$ressource = mysql_query($results,$connect);

$ressource = mysql_query($results,$connect);
$num_rows = mysql_num_rows($ressource);

?>



<Br>



<table cellpadding=3 border="1">
<tr><td>Preview</td><td>Name</td><td>URL</td><td>Username</td></tr>
<?php
require("databaseconnect.php");
while ($row = mysql_fetch_array($ressource, MYSQL_NUM)) {
    printf("<tr><td><img height=150 width=150 src=%s></td><td>%s</td><td><a href=%s>%s</a></td><td>%s</tr>", $row[2], $row[1], $row[2], $row[2], $row[0]); 
}


?>

There might be a special character in $username that is causing the error. You should be using mysql_real_escape_string() anyway.

hey till

$results = mysql_query("SELECT * FROM `pics` WHERE username='".$username."' LIMIT 1") or die(mysql_error());

or

$results = mysql_query("SELECT * FROM `pics` WHERE username='".$username."' LIMIT 1" , ,$connect) or die(mysql_error());

its fine now you have result set in $results.

Why are you agin and again asking database to give you result set when you already have it

#
$ressource = mysql_query($results,$connect);
#

#
$ressource = mysql_query($results,$connect);


remove these lines no need.

Now in

$num_rows = mysql_num_rows($ressource);


it should be

$num_rows = mysql_num_rows($results );

Your first error will go now.

Now coming to next error

while ($row = mysql_fetch_array($ressource, MYSQL_NUM)) {

change this to

while ($row = mysql_fetch_array($results , MYSQL_NUM)) {

It should work fine now


Also

Why are you adding same file again and again

require("databaseconnect.php"); ??

Hope this fixes your script if not let me know i iwll write complete code for you :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.