0

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 />

8
Contributors
14
Replies
16
Views
6 Years
Discussion Span
Last Post by Fest3er
Featured Replies
0
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!

0

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 />

0

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']}'";
0

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

Edited by karthik_ppts: n/a

0

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);
0

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);
		?>
1

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....

0

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);
		?>
0

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 :(

0

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);
		?>
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.