0

I have designed a simple code to fetch data using php but i am getting an error... Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in C:\xampp\htdocs\test.php on line 33 I have connected it with database without where clause condition it works but i need to run the code with condition so that i can fetch particular row.

<html lang="en">

<head>

    <title>user registration</title>
</head>
<body>
    <h1>Enter details</details></h1>
<form action="" method="GET">
    firstname:<input type="text" name="firstname"/><br/>
    lastname:<input type="text" name="lastname"/><br/>
    
    
    <input type="submit" name="submit"/>
</form>


</body>
</html>

<?php
//connect database 
$con=mysqli_connect("localhost:3307","root","","newdatabase") or die(mysqli_error());
//select all values from client table
$data="SELECT * FROM client where username='dsa'";
$val=mysqli_query($con,$data);          
while($r=mysqli_fetch_row($val))
{
echo $r[0]." ".$r[1];
}               
?>
  • if without condition works, probably there is no username='dsa', try username like '%dsa%' to make the filter "wider" this will match everything that has dsa in it – Roberto Braga Oct 10 '22 at 19:04
  • You clime `mysqli_fetch_array` cause to error. Please show code where you use this function – Slava Rozhnev Oct 10 '22 at 19:05
  • 1
    Your query failed, so it's returning `false` instead of a mysqli_result. Check for [mysqli errors](http://php.net/manual/en/mysqli.error.php) to find out why. – aynber Oct 10 '22 at 19:06
  • Remove `or die(mysqli_error())`. This line is completely wrong – Dharman Oct 11 '22 at 11:54

0 Answers0