0

can any1 tell me wats wrong in my code i cannt change my password using this code

<?php
$con=mysql_connect("localhost","root","");
 
	mysql_select_db("pras2");
if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

   

$username = $_POST['username']; 

$password = $_POST['password'];

$newpassword = $_POST['newpassword'];

$confirmnewpassword = $_POST['confirmnewpassword'];

 

$result = mysql_query("SELECT password FROM customer WHERE username='$username'");

 

    if(!$result){

        echo "The username entered does not exist!";

    }

    else

        if($password != mysql_result($result, 0)){

            echo "Entered an incorrect password";

            }

     

    if($newpassword == $confirmnewpassword){

        $sql = mysql_query("UPDATE customer SET password = '$newpassword' WHERE username = '$username'");      

    }

     

    if(!$sql){

        echo "Congratulations, password successfully changed!";

   }

    else{

        echo "New password and confirm password must be the same!";

    }

     

  ?>
3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by mikulucky
1

What exactly is the problem? For example do any of your errors display or does it appear to go trhough but doesn't actually update?
There are actually 2 errors in your code that I can see

else

        if($password != mysql_result($result, 0)){

            echo "Entered an incorrect password";

            }

You are missing the surrounding parenthesis for your else statement

else {

        if($password != mysql_result($result, 0)){

            echo "Entered an incorrect password";

            } }

Then you are saying if not $sql the success, should be the other way around

if($sql){

        echo "Congratulations, password successfully changed!";

   }
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.