0

So I have my query in which I am trying to get the "password" field to return because I am having issues with my login:

$res = $db->query("SELECT `password` FROM users WHERE username = 'joeybab3'");

and I get the error :

"object of class mysql_result cannot be converted to a string"

So some googling got me this:

list($res) = $res->fetch_row;

but that just returns blank when I use echo.

3 Answers 3

1

mysqli::query method returns a mysqli_result object. It is an object, that's why you cannot use echo to print it out.

You need to use fetch_array/fetch_assoc/fetch_row methods to really get the data out of it.

In this case, you could use:

$row = $res->fetch_assoc(); 
$password = $row['password'];
echo $password;
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I can now continue onward with a login system on my site!
0

fetch_row is a function, calling it like this should work.

list($res) = $res->fetch_row();

Edit:

Looks like you're using the MySQL library which has been deprecated. You should choose a different api if possible.

Comments

0

Then use this code:

$sql = "SELECT 'password' FROM users WHERE username = 'joeybab3'";

and echo $sql.

This is how I would do it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.