这是我非常简单和基本的帐户系统(只是一个学校项目),我希望用户能够更改他们的密码。但我不确定如何仅替换一行中的密码值,保持所有其他值相同。
CSV 文件:
ID,Username,Email,DateJoined,Password,UserScore,profilePics
1,Test,[email protected],03/12/2014,Test,10,uploads/profilePics/Test.jpg
2,Alfie,A[email protected],05/12/2014,1234,136,uploads/profilePics/Alfie.png
PHP:
(“cNewPassword”=确认新密码)
<?php
session_start();
if(empty($_POST['oldPassword']) || empty($_POST['newPassword']) || empty($_POST['cNewPassword'])) {
die("ERROR|Please fill out all of the fields.");
} else {
if($_POST['newPassword'] == $_POST['cNewPassword']) {
if ($_POST['oldPassword'] == $_SESSION['password']) {
$file = "Database/Users.csv";
$fh = fopen($file, "w");
while(! feof($file)) {
$rows = fgetcsv($file);
if ($rows[4] == $_POST['oldPassword'] && $rows[1] == $_SESSION['username']) {
//Replace line here
echo("SUCCESS|Password changed!");
}
}
fclose($file);
}
die("ERROR|Your current password is not correct!");
}
die("ERROR|New passwords do not match!");
}
?>