Hello,
I am using this code and getting this error given below:-

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\database login new\buyers_substance_view.php on line 46

Please check the code is given below:-

<?php
$title="Buyers Substance Report";
$page_name="Buyers Substance Report";
include("includes/header.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>company info search</title>
</head>

<body>


<div style='overflow:auto; height:300px;'id=buyer_detail>
<form action="buyer_substance_save.php" method="post">
<table border="1" align=center cellpadding=5 bgcolor="#CCCCCC">
<tr>
<th>Buyer Name</th>
<th>Substance Name</th>
<th>CAS No</th>
<th>EC no</th>
</tr>

<?php
$where="";
if(!empty($_GET)){
$s_name=$_GET;
$where="where c_id='$s_name'";
}


db_connect();

$qry="select * from company $where";

$result=mysql_query($qry);
$row=mysql_fetch_array($result);

echo $buyer_query="select * from buyers_detail where company_id='".$row."and buyer_id='".$_GET."'";

// $buyer_query="select * from buyer_detail where buyer_id='".$_GET."'";
$result2=mysql_query($buyer_query);

$buyer_query_result=mysql_fetch_array($result2);

$qry1="select * from substance where company_id='".$row."'";

$result1=mysql_query($qry1);
$qry2="select * from buyers_substances where buyer_id='".$_GET."'";

$result2=mysql_query($qry2);$substance_array=array();
while($row2=mysql_fetch_array($result2))
{
$substance_array[]=$row2;
}$count=0;
while($row1=mysql_fetch_array($result1))
{
$id=$row1;
if(in_array($id, $substance_array)){
echo"<tr><td>".$buyer_query_result."</td><td>".$row1."</td><td>".$row1."</td><td>".$row1."</td></tr>";
$count=1; }

}
if($count==0)
echo"<tr><td colspan=3><center>No Substance Found</center></td></tr>";
?>
<input type=hidden name=buyer_id value="<?php echo $_GET; ?>">
</table>
</div><br />

db_connect();
$qry="select * from company $where";
$result=mysql_query($qry);
if (!$result) {
    die('Invalid query: ' . mysql_error());
}
$row=mysql_fetch_array($result);

post the error message here!

Although hard to read, it appears that buyer_query needs a space before the AND.

hello,
thank you for reply,but still I am getting error.

error:- Invalid query: 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 '1' at line 1

please check the code is given below:-


<?php
$title="Buyers Substance Report";
$page_name="Buyers Substance Report";
include("includes/header.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>company info search</title>
</head>

<body>
<div style='overflow:auto; height:300px;'id=buyer_detail>
<form action="buyer_substance_save.php" method="post">
<table border="1" align=center cellpadding=5 bgcolor="#CCCCCC">
<tr>
<th>Buyer Name</th>
<th>Substance Name</th>
<th>CAS No</th>
<th>EC no</th>
</tr>

<?php
$where="";
if(!empty($_GET)){
$s_name=$_GET;
$where="where c_id='$s_name'";
}


db_connect();

$qry="select * from company $where";

$result=mysql_query($qry);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
$row=mysql_fetch_array($result);


echo $buyer_query="select * from buyer_detail where company_id='".$row. " AND buyer_id='".$_GET."'";

// $buyer_query="select * from buyer_detail where buyer_id='".$_GET."'";

$result2=mysql_query($buyer_query);

if (!$result2) {
die('Invalid query: ' . mysql_error());
}

$buyer_query_result=mysql_fetch_array($result2);

$qry1="select * from substance where company_id='".$row."'";

$result1=mysql_query($qry1);
$qry2="select * from buyers_substances where buyer_id='".$_GET."'";

$result2=mysql_query($qry2);$substance_array=array();
while($row2=mysql_fetch_array($result2))
{
$substance_array[]=$row2;
}$count=0;
while($row1=mysql_fetch_array($result1))
{
$id=$row1;
if(in_array($id, $substance_array)){
echo"<tr><td>".$buyer_query_result."</td><td>".$row1."</td><td>".$row1."</td><td>".$row1."</td></tr>";
$count=1; }

}
if($count==0)
echo"<tr><td colspan=3><center>No Substance Found</center></td></tr>";
?>
<input type=hidden name=buyer_id value="<?php echo $_GET; ?>">
</table>
</div><br />

Print all your query statements and execute it using phpmyadmin(or any mysql browser).

change your line with line given below

echo $buyer_query="select * from buyer_detail where company_id='{$row['c_id']}' AND buyer_id='{$_GET['buyer_id']}'";

You have missed the single quote before AND

$buyer_query="select * from buyer_detail where company_id='".$row['c_id']. "' AND buyer_id='".$_GET['buyer_id']."'";

Use code tags to post your code

Like other said check your query. You can use code below

db_connect();
$qry="select * from company $where";
die($qry);
$result=mysql_query($qry);
if (!$result) {
    die('Invalid query: ' . mysql_error());
}
$row=mysql_fetch_array($result);

Hey guys! I keep getting this error when querying my mysql database

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\query.php on line 46

( ! ) Warning: mysql_close() expects parameter 1 to be resource, object given in C:\wamp\www\query.php on line 52

<?php
			$host="localhost"; // Host name 
			$username="root"; // Mysql username 
			$password=""; // Mysql password 
			$db_name="informationdb"; // Database name 
			$tbl_name="file"; // Table name 
			
			// Connect to the database
            $dbLink = new mysqli("$host", "$username", "$password", "$db_name");
            if(mysqli_connect_errno()) {
                die("MySQL connection failed: ". mysqli_connect_error());
            } 
			
			$playerfname=$_POST["playerfname"];
			$playerlname=$_POST["playerlname"];
			$sport=$_POST["sport"];
			$season=$_POST["season"];
			$number=$_POST["number"];
			
			
			
			
			$playerfname=trim($playerfname);
			$playerlname=trim($playerlname);
			$sport=trim($sport);
			$season=trim($season);
			$number=trim($number);
			
			//require_once('mysql_connect.php'); 
			
			if (!$dbLink)
			{
				die('Could not connect: ' . mysql_error());
			}

			$result = mysql_query("
				SELECT *
				FROM file
				WHERE playerfname LIKE '%".$playerfname."%'
				AND playerlname LIKE '%".$playerlname."%'
				AND sport LIKE '%".$sport."%'
				AND season LIKE '%".$season."%'
				AND number LIKE '%".$number."%'
				");

			while($row = mysql_fetch_array($result))
			{
				echo $row['playerfname'] . " " . $row['playerlname'] . " " . $row['sport'] . " " . $row['season'] . " " . $row['number'];
				echo "<br />";
			}

			mysql_close($dbLink);
		?>

Don't you have to tell mysql_query *which* database connection it is to use for the query? As in mysql_query("select ...", $dbLink)? That's probably why mysql_fetch_array($result) is complaining that $result is not a valid resource....

ok thanks pritaeas. My query.php file(attached) is still throwing the same error though.. please help guys! Thanks.

<?php
			$host="localhost"; // Host name 
			$username="root"; // Mysql username 
			$password=""; // Mysql password 
			$db_name="informationdb"; // Database name 
			$tbl_name="file"; // Table name 
			
			// Connect to the database
            $con = mysql_connect("$host", "$username", "$password", "$db_name");
			
            if(!$con) {
                die("MySQL connection failed: ". mysql_error());
            } 
			
			$playerfname=$_POST["playerfname"];
			$playerlname=$_POST["playerlname"];
			$sport=$_POST["sport"];
			$season=$_POST["season"];
			$number=$_POST["number"];
			
			
			
			
			//$playerfname=trim($playerfname);
			//$playerlname=trim($playerlname);
			//$sport=trim($sport);
			//$season=trim($season);
			//$number=trim($number);
			
			
			$result = mysql_query("
				SELECT *
				FROM file
				WHERE playerfname LIKE '%".$playerfname."%'
				AND playerlname LIKE '%".$playerlname."%'
				AND sport LIKE '%".$sport."%'
				AND season LIKE '%".$season."%'
				AND number LIKE '%".$number."%'
				");

			while($row = mysql_fetch_array($result))
			{
				echo $row['playerfname'] . " " . $row['playerlname'] . " " . $row['sport'] . " " . $row['season'] . " " . $row['number'];
				echo "<br />";
			}
			
			mysql_close($con);
		?>

Don't you have to tell mysql_query *which* database connection it is to use for the query? As in mysql_query("select ...", $dbLink)? That's probably why mysql_fetch_array($result) is complaining that $result is not a valid resource....

that this is right:

<html> 
	<head></head>
	<body>
		<h1>Student Search Results</h1>
		
		<?php
		
			$searchID=$_POST['searchID'];
			$searchName=$_POST['searchName'];
			$searchMajor=$_POST['searchMajor'];
			$searchGrade=$_POST['searchGrade'];
			$searchGPA=$_POST['searchGPA'];
			
			$searchID=trim($searchID);
			$searchName=trim($searchName);
			$searchMajor=trim($searchMajor);
			$searchGrade=trim($searchGrade);
			$searchGPA=trim($searchGPA);
			
			require_once('../mysql_connect.php'); 
			
			if (!$db_link)
			{
				die('Could not connect: ' . mysql_error());
			}

			$result = mysql_query("
				SELECT *
				FROM student
				WHERE StudentID LIKE '%".$searchID."%'
				AND StudentName LIKE '%".$searchName."%'
				AND Major LIKE '%".$searchMajor."%'
				AND GradeLevel LIKE '%".$searchGrade."%'
				AND GPA LIKE '%".$searchGPA."%'
				");

			while($row = mysql_fetch_array($result))
			{
				echo $row['StudentID'] . " " . $row['StudentName'] . " " . $row['Major'] . " " . $row['GradeLevel'] . " " . $row['GPA'];
				echo "<br />";
			}

			mysql_close($db_link);
		?>
		
	</body>
</html>

but its not working for me :(

Don't you have to tell mysql_query *which* database connection it is to use for the query? As in mysql_query("select ...", $dbLink)? That's probably why mysql_fetch_array($result) is complaining that $result is not a valid resource....

i fixed it! thank you sir.

<?php
			$host="localhost"; // Host name 
			$username="root"; // Mysql username 
			$password=""; // Mysql password 
			
			
			// Connect to the database
            $con = mysql_connect("$host", "$username", "$password");
			
            if(!$con) {
                die("MySQL connection failed: ". mysql_error());
            } 
			
			
			$playerfname=$_POST["playerfname"];
			$playerlname=$_POST["playerlname"];
			$sport=$_POST["sport"];
			$season=$_POST["season"];
			$number=$_POST["number"];
			
			
			
			
			//$playerfname=trim($playerfname);
			//$playerlname=trim($playerlname);
			//$sport=trim($sport);
			//$season=trim($season);
			//$number=trim($number);
			
			$mydb=mysql_select_db("informationdb");
			
			$sql ="
				SELECT *
				FROM file
				WHERE playerfname LIKE '%".$playerfname."%'
				AND playerlname LIKE '%".$playerlname."%'
				AND sport LIKE '%".$sport."%'
				AND season LIKE '%".$season."%'
				AND number LIKE '%".$number."%'
				";
			$result=mysql_query($sql);
			while($row = mysql_fetch_array($result))
			{
				echo $row['playerfname'] . " " . $row['playerlname'] . " " . $row['sport'] . " " . $row['season'] . " " . $row['number'];
				echo "<br />";
			}
			
			mysql_close($con);
		?>

Oops. I missed that: selecting the DB to use. :( But at least I got the right neuron to fire!

To expand, you don't *have* to give mysql_query a DB object to use since it will (I believe) use the last one referenced. However, it's good practice to include it; future maintenance and debugging will be easier and there will be less hair loss.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.