partiz
partiz

Reputation: 1216

Illegal string offset with mysqli_fetch_assoc in mysqli

hi there I create this function to find password in a table if username is there!

but I got this error:

protected function checkLogin()
        {
            $conn = $this->connectDB();
            $password = mysqli_real_escape_string($conn, trim($_SESSION["password"]));
            $username = mysqli_real_escape_string($conn, trim($_SESSION["username"]));

        $conn = $this->connectDB();
                $record = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM profile WHERE email = '".$username."' OR cellphone = '".$username."' OR username = '".$username."'"));      

        if ($conn->error) 
        {
            echo $conn->error;
            $conn->close();
            return false;
        }
        $record = $record['password'];
        $conn->close();
        if($this->matchPasswords($record['password']))
            return true;
        return false;       
    }

error:

( ! ) Warning: Illegal string offset 'password' in F:\wamp\www\myweb\libs\core.php on line 383

what is my wrong?

Upvotes: 1

Views: 264

Answers (2)

Meher Jebali
Meher Jebali

Reputation: 289

>  $record = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM
> profile WHERE email = '".$username."' OR cellphone = '".$username."'
> OR username = '".$username."'"));

return a associative table , why you do this $record = $record['password']; ?

try to show the content by the function print_r

Upvotes: 1

syck
syck

Reputation: 3029

$record = $record['password'];
$conn->close();
if($this->matchPasswords($record['password']))

Most probably $record is now a string but not an array.

Upvotes: 3

Related Questions