Click here to Skip to main content
15,889,315 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Change password but first match current password and the update the new password. But I am getting error updating password with this code. Please help me.

<?php
	//session_start();
	//connect to database
	include "../pages/connect.php";
	//$db = mysql_connect("localhost", "root", "rangers", "doctor");
	/*if (!$db) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($db);*/


	if(isset($_POST['change_password_btn']))
	{
		$username = mysql_real_escape_string($_POST['user_id']);
		$password = mysql_real_escape_string($_POST['password']);
		$newpassword = mysql_real_escape_string($_POST['passwordnew']);
		
		if($row['password']==($password))
		{
		// update data in mysql database 
$sql="UPDATE registerdoctors SET password='$newpassword' WHERE doc_id='$username'" or die ("this stuffed up");
$result=mysql_query($sql) or die ("this stuffedup");
}

// if successfully updated. 
if($result){
//echo "Successful";
	?>
			  <script type="text/javascript">
              alert("password updated successfully.");
              window.location.href = '../pages/doctorwelcome.php?page=changepassword';
              </script>
              <?php
}

else {
//echo "error";
	?>
	 			<script type="text/javascript">
              alert("error updating...");
              window.location.href = '../pages/doctorwelcome.php?page=changepassword';
              </script>
              <?php

}




	
	}

	?>


What I have tried:

Change password but first match current password and the update the new password. But I am getting error updating password with this code. Please help me.
Posted
Updated 7-Apr-17 21:56pm

1 solution

You are storing passwords in clear text so your system is wide open to hacking. Please read Secure Password Authentication Explained Simply[^] and change your system urgently.
 
Share this answer
 

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