Jump to content

Archived

This topic is now archived and is closed to further replies.

simcoweb

Why is this returning 'Not Valid Resource' error?

Recommended Posts

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:

[code]<?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";
}
?>
[/code]

This returns this error:

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

Guidance? :)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Replace this line:
[code]<?php $results4 = mysql_query($sql4); ?>[/code]
with
[code]<?php $results4 = mysql_query($sql4) or die("Problem with the query: $sql4<br>" . mysql_error()); ?>[/code]

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

Ken

Share this post


Link to post
Share on other sites
Ok, that produced this:

[quote] 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[/quote]

Share this post


Link to post
Share on other sites
Your problem is probably the fact that your using the variable $SESSION in your query. Unless you created this yourself, the global is $_SESSION.

Share this post


Link to post
Share on other sites
also you need quotes around the data in your query. try it this way:

[code]

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

[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.