[英]How to Change Password In PHP
我在php中更改密碼頁面,我遇到了問題。 請指導我哪里有問題。
<form action="do_change_password.php" method="post">
<table width="70%" cellpadding="0" cellspacing="0" align="center" border="0">
<tr>
<td colspan="2" align="center">
<h2>CHANGE PASSWORD</h2>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td width="40%" height="30">Current Password
</td>
<td width="60%">
<input name="password" type="password" id="password" size="30"/>
</td>
</tr>
<tr>
<td height="30">New Password</td>
<td>
<input name="newpassword" type="password" id="newpassword" size="30"/>
</td>
</tr>
<tr>
<td height="30">Confirm New Password</td>
<td>
<input name="confirmnewpassword" type="password" id="confirmnewpassword" size="30"/>
</td>
</tr>
<tr>
<td height="30" colspan="2" align="center">
<input name="submit" type="submit" value="Submit" id="submit_btn"/>
<input name="reset" type="reset" value="Reset" id="reset"/>
</td>
</tr>
</table>
</form>
do_change_password.php
<?php
include 'includes/dbConnect.php';
$password = $_POST['password'];
$newpassword = $_POST['newpassword'];
$confirmnewpassword = $_POST['confirmnewpassword'];
$error_msg = "Field(s) cannot be empty";
if ($password == '' || $newpassword == '' ||$confirmnewpassword == '')
{
echo $error_msg;
exit;
}
$result = mysql_query("SELECT password FROM users WHERE password='$password'");
if
($password != mysql_result($result< 0))
{
echo "Entered an incorrect password";
}
if($newpassword == $confirmnewpassword)
{
$sql = mysql_query("UPDATE registration SET password = '$newpassword' WHERE password='$current_password'");
}
if(!$sql)
{
echo "Congratulations, password successfully changed!";
}
else
{
echo "New password and confirm password must be the same!";
}
?>
dbConnect.php
<?php
error_reporting(E_ERROR);
global $link;
$servername='localhost';
$dbname='school';
$dbusername='root';
$dbpassword='';
$table_Name="students";
$link = mysql_connect($servername,$dbusername,$dbpassword);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
else
{
mysql_select_db($dbname,$link) or die ("could not open db".mysql_error());
}
?>
我收到此錯誤,我無法更改密碼:輸入了錯誤的密碼。恭喜,密碼已成功更改! 無法更改密碼請告訴我我在哪里做錯。 提前致謝
我相信您在輸入標簽中將id
與name
混在一起。
更換...
<input name="current" type="password" id="password" size="30"/>
...與...
<input id="current" type="password" name="password" size="30"/>
基本上,您在輸入標簽中指定為name
任何內容都可以通過$_POST
獲得。
因此<input name="whatever" />
將是$_POST['whatever']
。
<input name="current" type="password" id="password" size="30" name="password"/>
$password = $_POST['password'];
$ _POST,它應該是html標記的接受名稱屬性。
嘗試用此..替換您的表單。您更改字段名的錯誤,並嘗試改進您的php代碼,請參見此SQL注入
<form action="do_change_password.php" method="post">
<table width="70%" cellpadding="0" cellspacing="0" align="center" border="0">
<tr>
<td colspan="2" align="center">
<h2>CHANGE PASSWORD</h2>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td width="40%" height="30">Current Password
</td>
<td width="60%">
<input name="password" type="password" id="password" size="30"/>
</td>
</tr>
<tr>
<td height="30">New Password</td>
<td>
<input name="newpassword" type="password" id="newpassword" size="30"/>
</td>
</tr>
<tr>
<td height="30">Confirm New Password</td>
<td>
<input name="confirmnewpassword" type="password" id="confirmnewpassword" size="30"/>
</td>
</tr>
<tr>
<td height="30" colspan="2" align="center">
<input name="submit" type="submit" value="Submit" id="submit_btn"/>
<input name="reset" type="reset" value="Reset" id="reset"/>
</td>
</tr>
</table>
</form>
<form action="do_change_password.php" method="post">
<table width="70%" cellpadding="0" cellspacing="0" align="center" border="0">
<tr>
<td colspan="2" align="center">
<h2>CHANGE PASSWORD</h2>
</td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td width="40%" height="30">Current Password
</td>
<td width="60%">
<input name="password" type="password" id="password" size="30"/>
</td>
</tr>
<tr>
<td height="30">New Password</td>
<td>
<input name="newpassword" type="password" id="newpassword" size="30"/>
</td>
</tr>
<tr>
<td height="30">Confirm New Password</td>
<td>
<input name="confirmnewpassword" type="password" id="confirmnewpassword" size="30"/>
</td>
</tr>
<tr>
<td height="30" colspan="2" align="center">
<input name="submit" type="submit" value="Submit" id="submit_btn"/>
<input name="reset" type="reset" value="Reset" id="reset"/>
</td>
</tr>
</table>
</form>
試試這個..它將正常工作。
您必須捕獲:
$password = $_POST['current'];
$newpassword = $_POST['new'];
$confirmnewpassword = $_POST['confirm-new'];
或替換輸入name
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.