所以,我正在尝试更改表用户中的密码,因为我正在使用以下 php 代码,但它没有得到更新。
<?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'";
?>
然后我尝试使用此代码,虽然我得到“更新成功”,但实际上它没有在数据库中更新,谁能告诉我错误在哪里。
<?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";
}
?>