0

I am making a website with registration and login. So I have a database where users information in stored. Now I want to get some info from this database. To be exact I want to get users password using PHP code. Right now my code is following:

<?php
    $result = mysql_query('SELECT password FROM users');
    echo mysql_result($result, 4);
?>

I get this message, when I try to run my code:

Warning: mysql_result(): Unable to jump to row 4 on MySQL result index 8 in C:\xampp2\htdocs\Praks\seaded.php on line 20

How could I make it work?

3
  • Why are you trying to jump to a specific row instead of using a WHERE user=? query? Commented Apr 12, 2014 at 16:49
  • u are selecting one field and jumping to 4th ? Commented Apr 12, 2014 at 16:49
  • You are using an obsolete database API and should use a modern replacement. Commented Apr 12, 2014 at 16:50

1 Answer 1

1

it seems that do not have 5 passwords rows stored in your database. so you can try :

 echo mysql_result($result, 0);//return first password from your query result

or you can do like this to echoing all passwords:

$result = mysql_query('SELECT password FROM users');
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    printf("password: %s ", $row["password"]);
}

notice: all mysql_* functions are deprecated. You should move to PDO or mysqli.

Sign up to request clarification or add additional context in comments.

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.