Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with mysql_query

Status
Not open for further replies.

dwardio

Programmer
May 17, 2001
5
US
I have a problem with the mysql_query() function...

Consider the following code:

<?php
$db = mysql_connect(&quot;host&quot;, &quot;user&quot;, &quot;pass&quot;);
$connect = mysql_select_db(&quot;webdemo&quot;,$db);

$query = &quot;SELECT COUNT(*) AS myCount, userType FROM survey GROUP BY userType&quot;;

$result = mysql_query($query, $db);

// DEBUGGING CODE:
printf (&quot;<h3>Debug Results:</h3>&quot;);
printf (&quot;db = $db <br>&quot;);
printf (&quot;connect = $connect<br>&quot;);
printf (&quot;query = $query<br>&quot;);
printf (&quot;result = $result<br>&quot;);

if(mysql_num_rows($result) >0) {
while($myrow = mysql_fetch_row($result)){
printf($myrow[myCount], $myrow[userType]);
}
} ELSE {
print &quot;<BR>ERROR: There are no rows!&quot;;
}
?>

When I run this, I get:
---
Debug Results:
db = Resource id #1
connect = 1
query = SELECT COUNT(*) AS myCount, userType FROM survey GROUP BY userType
result =

Warning: Supplied argument is not a valid MySQL result resource in c:/program files/abria merlin/apache/htdocs/report.php on line 25

ERROR: There are no rows!
---

Any ideas what can be causing this? The user in this case has both SELECT and INSERT privs in the mysql:user table, and can successfully insert new rows via another script...

I can successfully run the SELECT stmt in the mysql console and get the results that I want, so I'm satisfied that the SELECT is OK.

HELP!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top