Click here to Skip to main content
15,616,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to get password of sombody in table name in database mysql
<form action="GetPassword.php" method="post">
              <h3>Get Password by name</h3>
             <label>Name : </label>
             <input type="text" name="nameofpass" placeholder="Enter name to get password">   
              <input type="submit" name="getpass" value="Go"> 

What I have tried:

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "testdb";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error)
die("Connection failed: " . $conn->connect_error);
$query ="SELECT password from names where name='$name'";
   $result = mysql_query($query); 
    while ($row = mysql_fetch_array($result)) {
        echo $row['password'];
Updated 4-Jul-22 23:30pm
Richard Deeming 22-Jun-17 17:29pm    
NEVER store passwords in plain text, and NEVER display them to anyone!

Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]

remove coats for php variable i,e.,
$query ="SELECT password from names where name=$name";
Share this answer
change your query as
$query ="SELECT password from names where name=$name";

Hence $name is varable no need to use quotes,

Better if you use
fucntions in all sections

$result = mysqli_query($conn,$query); 
    while ($row = mysqli_fetch_array($result)) {
        echo $row['password'];
Share this answer
$query ="SELECT password from names where name=$name";
$result = mysql_query($query ,$query);
return $result ;
Share this answer
CHill60 5-Jul-22 6:54am    
Apart from the fact the question is 5 years old and already has an accepted answer, you have effectively just copied solution 3 - with one major mistake - the first parameter for mysql_query() is the connection. Passing the query twice will simply just not work.
Stick to answering more recent posts where the OP might actually remember the post, and make sure your solution is both accurate and brings something new to the thread

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900