So,i am trying to change the password in the table users,for that i am using the following php code,but it is not getting updated.
<?php
session_start();
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="bloodbank"; // Database name
$tbl_name="users"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username ,password and newpassword sent from form
$username=$_POST['username'];
$password=$_POST['password'];
$newpassword=$_POST['newpassword'];
$sql="UPDATE $tbl_name SET password='$newpassword' WHERE username='$username' and password='$password'";
?>
Then i tried to use this code,although i am getting "Updated Successfully",in reality it is not getting updated in the database,can anyone please tell me where error is.
<?php
session_start();
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="bloodbank"; // Database name
$tbl_name="users"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username,password and newpassword sent from form
$username=$_POST['username'];
$password=$_POST['password'];
$newpassword=$_POST['newpassword'];
$sql="SELECT * FROM $tbl_name WHERE username='$username' and password='$password'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
if($count==1)
{
$mysql="UPDATE $tbl_name SET password='$newpassword'";
echo "Updated Successfully";
}
else
{
echo "Wrong password or Username";
}
?>