简体   繁体   中英

How to get value of password from MySQL database using PHP

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM