Click here to Skip to main content
15,887,214 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
HTML
<form action="GetPassword.php" method="post">
         <legend>
              <h3>Get Password by name</h3>
        </legend>
        <fieldset>
           <p>
             <label>Name : </label>
             <input type="text" name="nameofpass" placeholder="Enter name to get password">   
           </p>
           <p>
              <input type="submit" name="getpass" value="Go"> 
           </p>    
        </fieldset>
    </form>


What I have tried:

PHP
<?php
if(isset$_POST['getpass'])
{
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "testdb";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
$name=$_POST['nameofpass'];
$query ="SELECT password from names where name='$name'";
   $result = mysql_query($query); 
    while ($row = mysql_fetch_array($result)) {
        echo $row['password'];
    }
    mysqli_close($conn);  
}
?>
Posted
Updated 4-Jul-22 23:30pm
v4
Comments
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
mysqli
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
 
Comments
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