By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,117 Members | 1,093 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,117 IT Pros & Developers. It's quick & easy.

Warning: mysql_fetch_field() expects parameter 1 to be resource, boolean given in C:\

P: 10
hi
i am getting this warning
Warning: mysql_fetch_field() expects parameter 1 to be resource, boolean given in :\wamp\www\phpclasses\inserttestdetails.php on line 62
my code is

please help me in finding mistake

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. //connection 
  3. $con = mysql_connect("localhost", "", "");
  4. if (!$con)
  5.   {
  6.   die('Could not connect: ' . mysql_error());
  7.   }
  8.  
  9. $db_selected = mysql_select_db("labreporter",$con);
  10.  
  11.   //getting selected check box fields into an array from      an html page
  12.   $testselection1 = $_POST['testselection'];
  13.  
  14. //my array  $alltestsarray=array("urinaryproteines","AEC","bgrhtype",                     "aia","agr","apt","cmbsd","ama");
  15.  
  16. //checking whether selected check box selected or not
  17.   if(empty($testselection1))
  18.   {
  19.     echo("You didn't select any tests.");
  20.   }
  21.   else
  22.   {
  23.     //counting selected text boxes
  24.     $N = count($testselection1);
  25.     //counting my array
  26.     $n1= count($alltestsarray);
  27.     for($i=0; $i < $N; $i++)
  28.     {
  29.       for($j=0; $j<$n1; $j++)
  30.     {
  31.      if($testselection1[$i]==$alltestsarray[$j])
  32.       {
  33.        echo("You selected $N tests: ");
  34.  
  35.            $result=mysql_query("select t.tid from
  36.                                testmaster t where 
  37.                                t.testname=
  38.                                '$testselection1[$i]'",      
  39.                                $con);
  40.         if($result>0)
  41.         {
  42.         while($myrow =mysql_fetch_field($result))
  43.             {
  44.             print "<br>".$myrow['t.tid']."";
  45.             echo($testselection1[$i] . ", ");
  46.                                 }
  47.         }
  48.  
  49.       }
  50.  
  51.     }
  52.     }
  53.   }
  54.  
  55. ?>
Jan 16 '12 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
your query failed. (in such a case mysql_query() returns (boolean) false). and $result ain't a number either, it's a resource (a data type). you can get the last error by mysql_error().

also, use mysql_fetch_assoc() instead of mysql_fetch_field(). the latter function is to provide DB metadata, not sql results.

despite the above said, mysql_* functions are terribly outdated. you should be using PDO or MySQLi.
Jan 16 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.