I cannot figure out why I am getting this error,

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, string given in
C:\Users\User\PhpstormProjects\assignment\index.php on line 217

My php code is as follows:

<?php session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<style type="text/css">
#contenair{
height: 100%;
width: 100%;

}
#r{
	margin-top: 5%;
	margin-bottom: 50px;
	margin-right: 20px;
	float: right;
	height:95%;
	width:35%;
	background-color: #b7bcbd;
	
}
#l
{
	margin-top: 5%;
	margin-bottom: 50px;
	margin-left:20px;
	float: left;
	
	width: 60%;
	background-color: #b7bcbd;

}
</style>

<script>


    function signup()
  {

      var alt="";
      var x=document.forms["signupform"]["firstname"].value;
      if (x==null || x=="")
        {
          alt +="First name must be filled out\n";
          
        
        }
     var y=document.forms["signupform"]["lastname"].value;
     if (y==null || y=="")
        {
          
          alt += "Last name must be filled out\n";
          
        }
		var x=document.forms["signupform"]["daytimephone"].value;
      if (x==null || x=="")
        {
          alt +="First name must be filled out\n";
          
        
        }
      var z=document.forms["signupform"]["email"].value;
      var atpos=z.indexOf("@");
      var dotpos=z.lastIndexOf(".");
          
       if (atpos<1 || dotpos<atpos+2 || dotpos+2>=z.length)
          {
         alt += "Not a valid e-mail address\n";
         
          }
     
      var v=document.forms["signupform"]["password1"].value; 
     
      if (v==null || v=="")
        {
          alt += "password must be filled out\n";
             
        }
     var t=document.forms["signupform"]["password2"].value; 
     if (t==null || t=="")
        {
          alt += "confirm password must be filled out\n";
            
        }
		 if (v != t)
        {
          alt += "password  doesn't  match\n";
             
        }
      if((document.forms["signupform"]["usertype1"].checked==false)&& (document.forms["signupform"]["usertype2"].checked==false))
  
        {
           alt += "payment type  must be filled out\n";
                 
        }
   
    if (alt != "")
         {
           alert(alt);
          return false;
         }
		 else {
		 	form.Submit()
		 }

}

 </script>

</head>
<body>
<div id="contenair">
<?php
include('include/db_con.php');
if(isset($POST['Submit']))
{
$fn=$
POST['firstname'];
$ln=$POST['lastname'];
$phone=$
POST['daytimephone'];
$email=$POST['email'];
$pass=$
POST['password1'];
$city=$POST['city'];
$country=$
POST['country'];
$intr=$_POST['usertype'];

$s1="INSERT INTO users (first_name,last_name,day_phone,user_name,user_password,city,country,payment_type)VALUES('".$fn."','".$ln."','".$phone."','".$email."','".$pass."','".$city."','".$country."','".$intr."')";
mysql_query($s1) or die (mysql_error($con));
}
?>
<div id="l" align="left">
<h2 align="center" style="color:red">Welcome to our Hotel </h2>
<h3 align="center"><u><i>Create A Account For New User....</i></u></h3>
<table>
<form method="POST" name="signupform" action="index.php" onSubmit="return signup();" >
<tr>
<td height="40">FirstName:</td>
<td><input name="firstname" type="text" id="firstname" size="40" />

	</td>
</tr>
<tr>
	<td height="40">LastName:</td>
	<td><input name="lastname" type="text" id="lastname" size="40"  />
	
	</td>
</tr>
<tr>
	<td height="40">Phone:</td>
	<td><input name="daytimephone" type="text" id="daytimephone" size="40" class="phone" />
	
	</td>
</tr>
<tr>
	<td height="40">E-mail:</td>
	<td><input name="email" type="text" id="email" size="40"  />
	
	</td>
</tr>

<tr>
	<td height="40">Password:</td>
	<td><input name="password1" type="password" id="password1" size="40" />
	
	</td>
</tr>
<tr>
	<td height="40">Confirm Password:</td>
	<td><input name="password2" type="password" id="password2" size="40" />
	
	</td>
</tr>
<br>
<tr>
	<td height="40">City/State</td>
	<td><input name="city" type="text" id="city" size="40"  />
	</td>
</tr>
<br>
<tr>
	<td height="40">Country</td>
	<td><input name="country" type="text" id="country" size="40" />
	
	</td>
</tr>
<br>
<tr>
	<td>Payment Type:</td>
	<td><input type="radio" name="usertype" id="usertype1" value="cash" />Cash
	<input type="radio" name="usertype" id="usertype2" value="paypal" />Paypal/CreditCard
	</td>
</tr>
<tr>
<td align="center" colspan="2"><input type="submit" name="Submit" value="Submit" />
	<input type="reset" name="reset" value="Reset"  /></td></tr>
</form>

</table>
</div>
<div id="r" align="right">

    <?php
    	include('include/db_con.php');
	if (isset($_POST['username'],$_POST['password']))
		   {
            $username=$_POST['username'];
            $password=$_POST['password'];

               if (empty($username) || empty($password))
               {
                  $error = 'Hey All fields are required!!';
                }

				 else {
				 $login="select * from users where user_name='".$username."' and user_password ='".$password."'";
				 $result=($login);
				 mysqli_query ($con,$result);
				 print_r($result);


				if(mysqli_fetch_array($result)){
			 $_SESSION['logged_in']='true';
			 $_SESSION['username']=$username;
				 header('Location:registration.php');
				 exit();
				 } else {
				 $error='Incorrect details !!';
				 }
				       }
	}

?>
<form action="index.php" method="POST">
<h2 align="center" id="h"><u><i>Login Here........</i></u></h2>
<table align="center" id="t">
<tr> <?php if (isset($error)) {?>
<small style="color:#aa0000;"><?php echo $error; ?>
<br /> <br />
<?php } ?> </tr>
<tr>
<td width="113">Email:</td>
<td width="215">
<input name="username" type="text" size="40" /></td>
</tr>
<tr>
<td>Password:</td>
<td>
<input name="password" type="password" size="40" /></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="sub" value="Login" /></td>
</tr>

   </table>
	</form>
	
	
</div>

</div>
</body>
</html>

    <?php
    //$con=mysql_connect("localhost","root","");
    //mysql_select_db("assignment",$con) or die(mysql_error($con));
    //error_reporting(E_ALL ^ E_NOTICE);
    $con=mysqli_connect("localhost","root","","assignment");
    $login = "SELECT FROM users";
    $result = mysqli_query($con,$login) or die( mysqli_error($con));
    //$result=mysqli_query($con,"select
    from users");

    while ($row=mysqli_fetch_array($result))

    ?>

      I can't be bothered trawling through all that trying to count which line is 217 or what leads up to it, though I doubt it's anywhere in that CSS or JavaScript; but the error message gives a very clue as to where to look for the cause of the problem.

      Though maybe you should look at

      $login="select * from users where user_name='".$username."' and user_password ='".$password."'";
      				 $result=($login);
      				 mysqli_query ($con,$result);
      				 print_r($result);
      
      
      				if(mysqli_fetch_array($result))

        It looks like your reply to yourself should be closer to what you want. Is that working now?

        In any case, you can help us help you by utilizing this board's [code]...[/code] tags around any code snippets, and as alluded to above, trying to reasonably limit the code you post to that which may actually be contributing to the problem.

        And welcome to PHPBuilder. 🙂

          Weedpacket hit it on the head.

          $result=($login);
          				 mysqli_query ($con,$result);
          				 print_r($result);
          
          
          			if(mysqli_fetch_array($result))

          In the first line quoted you assign $result to be a string, and in the last line quoted you call mysqli_fetch_array() on it. "mysqli_fetch_array expects parameter 1 to be mysqli result" ... not a string.

          But don't worry, we've all had egg on our face more than once in our lives, and we've survived. Part of the problem here might have been choosing a good name; a variable named $result seems to tell us it's a result, but since you assigned it to be a string the variable name became something of a liar. 😃 (Not you, the variable name 😉 )

          You're much closer in your 2nd post, where you've actually got $result being the return from mysqli_query() and then use a variable ($row) as a token for iterating through a while() loop.

          As Weedpacket reminded me recently: "There are 2 hard problems in computer science: cache invalidation, naming things, and off-by-1 errors. --- Leon Bambrick"

            Write a Reply...