1

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?

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
partiz
  • 1,206
  • 2
  • 13
  • 34
  • check this out , you may find your solution there: http://stackoverflow.com/questions/9869150/illegal-string-offset-warning-php – Meher Jebali Sep 09 '15 at 11:11

2 Answers2

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

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

syck
  • 2,984
  • 1
  • 13
  • 23
1
>  $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

Meher Jebali
  • 199
  • 2
  • 3
  • 18