Warning: mysql_num_fields(): supplied argument is not a valid MySQL result resource on PHP page

I keep getting two errors on my php page when running my query.  The two errors are:

Warning: mysql_num_fields(): supplied argument is not a valid MySQL result resource in interpret.php on line 64

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in interpret.php on line 68
 
I can successfully run the query directly on my database and the sql statement runs fine. Here is my code for the page.

$conn = phpmkr_db_connect(HOST, USER, PASS, DB, PORT);

$siteid = $_GET['siteid'];
$controller = $_GET['controller'];

$result = "select distinct c.name,c.ssid,c.number,c.batchnum, c.exename
     from marketsonjobs m INNER JOIN mcast c ON c.ssid = m.ssid
     WHERE m.controller = '$controller' AND m.market = '$siteid' AND c.display = 'yes'
     AND c.active = 'yes' GROUP BY c.name;";

if (!$result) {
   echo 'Could not run query: ' . mysql_error();
   exit;
}

// Create table from results

$number_of_fields=mysql_num_fields($result);
   
echo "<table border=1 cellspacing=0 cellpadding=0>";
$flag=0;
     while($row=mysql_fetch_array($result))
{
     if($flag==0)

     for($r=0;$r<$number_of_fields;$r++)
    echo "<th><td bgcolor=#E8E8E8><b>".mysql_field_name($result,$r)."</td></th>";
      
$flag=1;
    echo "<tr>";

     for($r=0;$r<$number_of_fields;$r++)

    echo "<td>&nbsp;".$row[$r]."</td>";
    echo "</tr>";
}
    echo "</table>";


?>

Any help would be greatly appreciated.

Wayneray
waynerayAsked:
Who is Participating?
 
Muhammad WasifCommented:
Change
$result = "select distinct c.name,c.ssid,c.number,c.batchnum, c.exename
     from marketsonjobs m INNER JOIN mcast c ON c.ssid = m.ssid
     WHERE m.controller = '$controller' AND m.market = '$siteid' AND c.display = 'yes'
     AND c.active = 'yes' GROUP BY c.name;";

to

$query = "select distinct c.name,c.ssid,c.number,c.batchnum, c.exename
     from marketsonjobs m INNER JOIN mcast c ON c.ssid = m.ssid
     WHERE m.controller = '$controller' AND m.market = '$siteid' AND c.display = 'yes'
     AND c.active = 'yes' GROUP BY c.name;";

$result = mysql_query($query);
0
 
dr_dedoCommented:
your problem was that you didn't run the query in the first place as wasif mentioned.

you may need to add a line where u select whic databse to use
$conn = mysql_select_db('databseName');


and i'd add to wasif's comment, last line in his code
$result = mysql_query($query) or die (mysql_error());
0
 
waynerayAuthor Commented:
I feel sort of stupid. I still love PHP.  Thanks a bunch.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.