我創建了一個PHP腳本,該腳本允許我網站上的用戶在註冊後更改其密碼,但當我嘗試在網站上打開它時出現錯誤。我相信這是由於我的語法錯誤,但我似乎無法發現它。有人可以看一看,看看你能找到什麼嗎?下面是該腳本:在PHP中更改密碼腳本時出錯
<?php
session_start();
$user = $_SESSION['username'];
if ($user)
{
//user is logged in
if ($_POST['submit'])
{
//start changing password
//check fields
$oldpassword = md5($_POST['oldpassword']);
$newpassword = md5($_POST['newpassword']);
$repeatnewpassword = md5($_POST['repeatnewpassword']);
//check password against db
include('connection.php');
$queryget = mysql_query("SELECT password FROM Users WHERE username='$user'") or die ("change password failed");
$row = mysql_fetch_assoc($queryget);
$oldpassworddb = $row['password'];
//check passwords
if ($oldpassword==$oldpassworddb)
{
//check two new passwords
if ($newpassword==$repeatnewpassword)
{
//successs
//change password in db
$querychange = mysql_query("UPDATE Users SET password='$newpassword' WHERE username='$user'");
session_destroy();
die("Your password has been changed. <a href='homepage.php'> Return</a>");
}
else
die("Old password doesn't match!");
}
else
echo"
<form action='changepassword.php' method='POST'>
Old Password: <input type='text' name='oldpassword'><p>
New Password: <input type='password' name='newpassword'><p>
Repeat New Password: <input type='password' name='repeatnewpassword'><p>
<input type='submit' name ='submit' value='submit'>
</form>
";
}
else
die ("You must be logged in to change your password");
}
?>
我得到的錯誤如下:
公告:未定義的索引:在提交上/var/www/localhost/htdocs/changepassword.php線11 你必須登錄後更改密碼。
在此先感謝您的幫助。
可能是這個環節也http://stackoverflow.com/q/ 12859942/1723893 :) – 2013-05-11 14:21:42
感謝您的鏈接更新 – konnection 2013-05-11 14:26:50
現在我只是得到「您必須登錄才能更改密碼」有沒有一種方法可以解決這個問題。我目前登錄。 – Nick 2013-05-11 14:29:41