mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given

<?php include 'dbConfig.php';
 
       
      //$res=mysqli_query($db,"Select f.fname,f.sname,f.mail,f.num,f.gen,s.tadd,s.padd,s.amail,s.anum,s.status from first f,second s ");
        $sql2 = "Select f.fname,f.sname,f.mail,f.num,f.gen,s.tadd,s.padd,s.amail,s.anum,s.status from first f,second s";
               

                  $result2 = mysqli_query($db, $sql2) or die("Error: ".mysqli_error($db));
                 
echo "<tr><td colspan='5'></td></tr>";
             while($row = mysqli_fetch_array($result2))  
                          {  
                               echo '  
                               <tr>  
                                    <td>'.$row["f.fname"].'</td>  
                                    <td>'.$row["f.sname"].'</td>  
                                    <td>'.$row["f.mail"].'</td>  
                                    <td>'.$row["f.num"].'</td>  
                                    <td>'.$row["f.gen"].'</td>  
                                    <td>'.$row["s.tadd"].'</td>  
                                    <td>'.$row["s.padd"].'</td>  
                                    <td>'.$row["s.amail"].'</td>  
                                    <td>'.$row["s.anum"].'</td>  
                                    <td>'.$row["s.status"].'</td>  
                                     
                                     
                               </tr>  
                               ';  
                          }  
 
  ?>
  </table>
</div>
shruti Aweb developerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dan CraciunIT ConsultantCommented:
If you echo $result2 you'll see it's false.

Don't use die on your scripts. Treat your errors. Either with a try/catch or with a simple
if ($result2 == FALSE) printf("Error: %s\n", mysqli_error($db));

HTH,
Dan
Dave BaldwinFixer of ProblemsCommented:
The most common cause for that error is that the connection to the database server failed.
shruti Aweb developerAuthor Commented:
Im not getting what to do
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

Jim RiddlesPrepress/OMS SpecialistCommented:
Add the following line immediately after creating your $db object:
var_dump($db);

Open in new window

Does it display a valid mysqli database object?
NerdsOfTechTechnology ScientistCommented:
What is happening is that there is an error in the query (invalid tables or something is not right in the SQL statement); so $results2 becomes false(boolean) instead of a mysqli_result object; therefore, you need to catch that error/return type before running code that requires a certain data type such as mysqli_fetch_array(). To do this you need a CONTROL STRUCTURE such as an if/else statement block (see line 6 below)

<?php 
	include 'dbConfig.php';
	//$res=mysqli_query($db,"Select f.fname,f.sname,f.mail,f.num,f.gen,s.tadd,s.padd,s.amail,s.anum,s.status from first f,second s ");
	$sql2 = "Select f.fname,f.sname,f.mail,f.num,f.gen,s.tadd,s.padd,s.amail,s.anum,s.status from first f,second s";
	$result2 = mysqli_query($db, $sql2);
	if($result2){
		echo "<tr><td colspan='5'></td></tr>";
		while($row = mysqli_fetch_array($result2))  
		{  
			echo '  
				<tr>  
					<td>' . $row["f.fname"]		. '</td>  
					<td>' . $row["f.sname"]		. '</td>  
					<td>' . $row["f.mail"]		. '</td>  
					<td>' . $row["f.num"]		. '</td>  
					<td>' . $row["f.gen"]		. '</td>  
					<td>' . $row["s.tadd"]		. '</td>  
					<td>' . $row["s.padd"]		. '</td>  
					<td>' . $row["s.amail"]		. '</td>  
					<td>' . $row["s.anum"]		. '</td>  
					<td>' . $row["s.status"]	. '</td>  
				</tr>  
			';  
		} 
	}else{
		echo "Error: " . mysqli_error($db);
	}
?>
  </table>
</div>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jim RiddlesPrepress/OMS SpecialistCommented:
With no further input from the author, the solutions answer the question.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.