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!";

    }

     

  ?>

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!";

   }

@simplypixie be me to it :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.