我试图从命令行进行身份验证,但不能很好地工作。请检查我的代码,让我知道我哪里出错了。
<?php
echo "enter your username\n";
$username = fgets(STDIN);
echo "your password\n";
$password = fgets(STDIN);
echo "enter your new password\n";
$newpassword = fgets (STDIN);
//connecting to database
$db = mysql_connect("localhost","sqldata","sqldata") or die(mysql_error());
//selecting our database
$db_select = mysql_select_db("accounts", $db) or die(mysql_error());
$sql = mysql_query ("select * from uptable where username ='$username'");
$result = mysql_fetch_assoc($sql);
$oldpassword = $result['password'];
if ($password != $oldpassword)
{
echo "error";
}
else
{
mysql_query("update uptable set password = '$newpassword' where username ='$username'");
echo "Your Password has been successfully changed";
}
?>