i have created one form for user to change the password for which programming is as bellow-
include("../database.php");
if(isset($_SESSION['user_name']))
{
$password=$_POST['new_password'];
$query="select password from login where username = '".$_SESSION['user_name']."' and password='".md5($password)."'";
echo $query."<br>\n";
$result=mysql_query($query) or die(mysql_error());
echo $result."<br>\n";
echo "abc<br>\n";
echo mysql_num_rows($result)."<br>\n";
if(mysql_num_rows($result))
{
echo "def";
$row=mysql_fetch_row($result);
$pass=$row['password'];
echo $pass;
if($pass==$password)
{
$query2="UPDATE login SET password='$password' WHERE username='$_SESSION[user_name]'";
echo $query2;
echo "Password changed successfully";
}
else
{
echo "You entered wrong current password";
}
}
else
{
echo "here";
}
}
else
{
header('Location:index.php');
}
It gives $result=0. So it doesn't going to update user password . it directly goes to else part and gives output "here" as written. what is the solution for that.
$_POST['new_password'], and then an UPDATE using that same value. Surely you should be using the existing password for the SELECT, as their password won't be changed at that point?'".$_SESSION[user_name]."'