Jump to content


Photo

Why is this returning 'Not Valid Resource' error?


  • Please log in to reply
7 replies to this topic

#1 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 04 October 2006 - 03:50 PM

I'm confused since I have several working scripts using identical code. But for some reason I can't see why this setup is a problem:

<?php 
$sql4 = "SELECT * FROM plateau_pros WHERE username=".$SESSION['username'].""; $results4 = mysql_query($sql4);

while ($row4 = mysql_fetch_array($results4)) { echo "<table width\"500\" border=\"0\"> <tr><td
bgcolor=\"#c0c0c0\"><class =\"bodytext\"><b>Name: </b></td> <td bgcolor=\"#e0e0e0\"><class=\"bodytext\">". $row4['firstname'] ." " .$row4['lastname'] ."</td></tr>
<tr><td bgcolor=\"#c0c0c0\"><class =\"bodytext\"><b>Business: </b></td>
<td bgcolor=\"#e0e0e0\"><class =\"bodytext\">testing testing testing ". $row4['business'] ."</td></tr> 
<tr><td bgcolor=\"#c0c0c0\"><class =\"bodytext\"><b>Title: </b></td> 
<td bgcolor=\"#e0e0e0\"><class =\"bodytext\">". $row4['title'] ."</td></tr> 
<tr><td bgcolor=\"#c0c0c0\"><class =\"bodytext\"><b>Phone: </b></td> 
<td bgcolor=\"#e0e0e0\"><class =\"bodytext\">".	$row4['phone'] ."</td></tr> 
<tr><td bgcolor=\"#c0c0c0\"><class =\"bodytext\"><b>Mobile:</b></td> 
<td bgcolor=\"#e0e0e0\"><class =\"bodytext\">". $row4['mobile'] ."</td></tr> 
<tr><td bgcolor=\"#c0c0c0\"><class =\"bodytext\"><b>Fax: </b></td> 
<td bgcolor=\"#e0e0e0\"><class =\"bodytext\">". $row4['fax'] ."</td></tr> 
<tr><td bgcolor=\"#c0c0c0\"><class =\"bodytext\"><b>Email: </b></td> 
<td bgcolor=\"#e0e0e0\"><class =\"bodytext\">".	$row4['email'] ."</td></tr> 
<tr><td bgcolor=\"#c0c0c0\"><class =\"bodytext\"><b>URL: </b></td> 
<td bgcolor=\"#e0e0e0\"><class =\"bodytext\">". $row4['url'] ."</td></tr> 
<tr><td	bgcolor=\"#c0c0c0\"><class =\"bodytext\"><b>Details: </b></td> 
<td bgcolor=\"#e0e0e0\"><class =\"bodytext\">". $row4['details'] ."</td></tr> 
<tr><td bgcolor=\"#c0c0c0\"><class =\"bodytext\"><b>Specialties: </b></td> 
<td bgcolor=\"#e0e0e0\"><class =\"bodytext\">".	$row4['specialties'] ."</td></tr> </table>\n";
} 
?>

This returns this error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home2/wwwxxxx/public_html/members-view.php on line 271


Guidance? :)

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 04 October 2006 - 04:33 PM

Im sorry, but whatever editor your using is making your code impossible to read, but generally, that error meens your query failed. try checking it for success before attempting to use its results.

#3 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 04 October 2006 - 04:45 PM

Sorry about that. I didn't preview the post first. Not sure why the code all freaked out. Anyway, I fixed it so it's readable now.

Ok, i'll check the query for success and post back.

#4 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 04 October 2006 - 04:49 PM

Also... please use the [ php ] [ / php ] tags. Much easier on the eye.

ps; Your problem is probably the fact that your using the variable $SESSION in your query. Unless you created this yourself, the global is $_SESSION.

#5 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 04 October 2006 - 04:50 PM

Replace this line:
<?php $results4 = mysql_query($sql4); ?>
with
<?php $results4 = mysql_query($sql4) or die("Problem with the query: $sql4<br>" . mysql_error()); ?>

This will tell you what's wrong with your query.

Ken

#6 simcoweb

simcoweb
  • Members
  • PipPipPip
  • Advanced Member
  • 1,102 posts
  • LocationCA

Posted 04 October 2006 - 05:11 PM

Ok, that produced this:

Problem is this: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 '' at line 1



#7 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 04 October 2006 - 05:49 PM

Your problem is probably the fact that your using the variable $SESSION in your query. Unless you created this yourself, the global is $_SESSION.

#8 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 04 October 2006 - 06:00 PM

also you need quotes around the data in your query. try it this way:


$sql4 = "SELECT * FROM plateau_pros WHERE username='{$_SESSION['username']}'";


Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users