troubleshooting Question

If MYSQLi result = "0", include x...

Avatar of nikaotech
nikaotech asked on
PHPMySQL Server
14 Comments1 Solution456 ViewsLast Modified:
Hello Experts,

I'm trying to dynamically place one of two menus on a page based on the result of a select statement.  It's actually working, but it's also throwing a couple of errors at the same time.  I am basically checking to see if the value of "dependent_id" is "0" or not.  That field is an integer with values from 0-12. If the value is "0" I need to include "menu1.php".  If it's anything else, "menu2.php".  The determination of which menu to use is working correctly, but as I mentioned, it's also throwing these two errors:

 
Error 1:
Warning: mysqli_fetch_row() expects parameter 1 to be mysqli_result, string given on line:
      while($row=mysqli_fetch_row($result))


Error 2:
Warning: mysqli_free_result() expects parameter 1 to be mysqli_result, string given on line:
      mysqli_free_result($result);


Here is that entire section...
<?php 
 $host = "localhost";
 $username = "user";
 $password = "pass";
 $db_name = "db";
 $db = new mysqli($host, $username, $password, $db_name);
 
 if(mysqli_connect_errno()) {
     echo "Error: Could not connect to database.";
     exit;
 }
		$query="select dependent_id from clients WHERE client_id='".$mysqli->real_escape_string($_REQUEST['client_id'])."'";
		$result = $db->query($query);

			while($row=mysqli_fetch_row($result))
				{  
				if($result = "0"){
					 include("menu1.php");
					}
				else
					{
					include("menu2.php");
					}
				}
		mysqli_free_result($result); 
		$db->close();
?>

Many thanks for any help!
ASKER CERTIFIED SOLUTION
Slick812

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 14 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 14 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros