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'];
}