473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

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
1 5408
Dormilich
8,658 Expert Mod 8TB
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

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

Similar topics

1
by: Mini Mouse | last post by:
Hiya folks, I'm getting the following error(s) below and I'm at a bit of a loss as to how to correct it. When I give it a parameter it then complains it needs two parameters and the second one...
2
by: J˙Giusł vs ::NRG::ius | last post by:
Hi all. I have this script ----------------------------------------------------------- <?php $doc = new DOMDocument(); $doc->load('books.xml'); echo $doc->saveXML(); ?>
1
by: malayappa | last post by:
Hi All here is the error what i m getting Warning: domdocument::domdocument() expects parameter 2 to be long, string given in D:\Program Files\Apache Software...
3
by: ghjk | last post by:
I want to expire user account in my php application. Below is my code . But i got "mktime() expects parameter 6 to be long, string given in ". Could anyone tell me what is wrong? Please.. ...
7
by: roseple | last post by:
Hi, can anyone please help me why I got this error every I uploaded files. Error: Here is the code on the said warning message: # Gather all required data $name =...
1
Paul NIcolai Sunga
by: Paul NIcolai Sunga | last post by:
what is wrong with my code? $Link = mysqli_connect("localhost","root","tupi"); if (!$Link) { die("Could not connect: " . mysql_error()); }...
1
by: dragos42 | last post by:
m from Romania and I bought the book let yourself, bother with a problem to conduct script 14.2 appear: The file has been uploaded! Warning: mysqli_query() expects parameter 1 to be mysqli,...
12
by: Rana Chakra | last post by:
<?php $username="root"; $password=""; $database="lko_phone"; $host="localhost"; $msg=""; mysql_connect($host,$username,$password); @mysql_select_db($database); if($_SERVER == "POST")
3
by: mocha | last post by:
I have this error message --> Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\script.php on line 24 You have an error in your SQL syntax; check the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.