0

I don't know where the issue is since am still getting this MySQL error

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, bool given in /opt/lampp/htdocs/Frika/inc/connect.php on line 20

<?php

$servername = "localhost";
$username = "roo";
$password = "Tri";
$dbname = "frika";

$con = mysqli_connect($servername, $username, $password, $dbname);

    // Check connection
if ($con->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} else {
    $query = "SELECT * FROM admin_users WHERE username = 'alex' and psw ='1234'";
    $result = mysqli_query($con, $query);

    if ($result = true) {
        while ($row = mysqli_fetch_assoc($result)) {
            echo $row['id'];
        }
    } else {
        echo "0 results";
    }
}
Dharman
  • 30,962
  • 25
  • 85
  • 135
Gatua
  • 1
  • 1
    The problem is your `if` statement. `$result=true`. You need to get rid of this if and it will work. – Dharman Apr 19 '20 at 13:08
  • Please read: [Should we ever check for mysqli_connect() errors manually?](https://stackoverflow.com/q/58808332/1839439) – Dharman Apr 19 '20 at 13:10
  • rather, change it to if ($row = mysqli_fetch_assoc($result)) { echo $row['id']; } } else { echo "0 results"; } – Your Common Sense Apr 19 '20 at 13:26

0 Answers0