希望我的用户能够更改用户密码
want my users to be abble to change the userpassword
我的网站上有一个允许用户更改密码的页面
表单要求输入用户名、当前密码、新密码、确认新密码。
如果用户输入所有信息弹出脚本请正确填写表格
并显示一条错误消息
(Notice: Undefined variable: wtbusers in
/home/www/hostname/dr/filename on line 16
Warning: mysql_num_rows(): supplied argument is not a valid MySQL
result resource in /home/www/hostname/dr/filename on line 20)
我的代码贴在下面,如果有人能帮忙,将不胜感激!谢谢!
蒂娜
更改密码信息屏幕:
<div id="inlogscherm">
<form name="form1" method="post" action="changepw.php">
<div class="textm">Change password</div><br>
<div class="text">Username:</div><div class="invulbalkje"><? echo "{$_SESSION['username']}"; ?></div><br />
<input name="username" type="text" id="username" value="<? echo "{$_SESSION['username']}"; ?>">
<div class="text">Password:</div><input name="pin" type="password" id="pin" class="invulbalkje"><br />
<div class="text">New Password:</div><input name="newpassword" type="password" id="newpassword" class="invulbalkje"><br />
<div class="text">Repeat New Password:</div><input name="repeatnewpassword" type="password" id="repeatnewpassword" class="invulbalkje"><br />
<input type="submit" name="Submit" value="Change" class="button">
</form>
这里是 php 的变化。(changepw.php)
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
include 'db.php';
$username = $_POST['username'];
$pin = $_POST['pin'];
$newpassword = $_POST['newpassword'];
$repeatnewpassword = $_POST['repeatnewpassword'];
$encrypted_password=md5($pin);
$encrypted_newpassword=md5($newpassword);
$result = mysql_query("SELECT pin FROM $wtbusers WHERE username='$username' and pin = '$pin'");
if(!$result)
{
echo"<script>alert('Please Fill Form Correctly')</script>"; }
if(mysql_num_rows($result)){
if($newpassword==$repeatnewpassword){
$sql=mysql_query("UPDATE $wtbusers SET pin='$pin' where username='$username'");
if($sql)
{
header("location:success.php");
}
else
{
header("location:error3.php");
}
} else {
header("location:error_password_not_matched.php");
}
} else {
echo"<script>alert('Please Fill Form Correctly')</script>";
}
?>
如果您发现问题,请与我联系。对此我将不胜感激!
请注意,您尚未创建名为 $wtbusers.
的变量
$wtbusers = 'users
'; //这应该被定义(将其更改为您的任何 table 名称)
试试下面的代码。
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
include 'db.php';
// print_r($_POST);
if (isset($_POST['username'])) {
$username = $_POST['username'];
}
if (isset($_POST['pin'])) {
$pin = $_POST['pin'];
}
if (isset($_POST['newpassword'])) {
$newpassword = $_POST['newpassword'];
}
if (isset($_POST['repeatnewpassword'])) {
$repeatnewpassword = $_POST['repeatnewpassword'];
}
$encrypted_password = md5($pin);
$encrypted_newpassword = md5($newpassword);
$wtbusers = '`users`'; //this should be defined (change this to your whatever table name)
$result = mysql_query("SELECT pin FROM $wtbusers WHERE username='$username' and pin = '$pin'");
if (!$result) {
echo "<script>alert('Please Fill Form Correctly')</script>";
}
if (mysql_num_rows($result) != 0) {
if ($newpassword == $repeatnewpassword) {
$sql = mysql_query("UPDATE $wtbusers SET pin='$pin' where username='$username'");
if ($sql) {
header("location:success.php");
}
else {
header("location:error3.php");
}
}
else {
header("location:error_password_not_matched.php");
}
}
else {
echo "<script>alert('Please Fill Form Correctly')</script>";
}
我的网站上有一个允许用户更改密码的页面
表单要求输入用户名、当前密码、新密码、确认新密码。
如果用户输入所有信息弹出脚本请正确填写表格
并显示一条错误消息
(Notice: Undefined variable: wtbusers in /home/www/hostname/dr/filename on line 16
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/www/hostname/dr/filename on line 20)
我的代码贴在下面,如果有人能帮忙,将不胜感激!谢谢!
蒂娜
更改密码信息屏幕:
<div id="inlogscherm">
<form name="form1" method="post" action="changepw.php">
<div class="textm">Change password</div><br>
<div class="text">Username:</div><div class="invulbalkje"><? echo "{$_SESSION['username']}"; ?></div><br />
<input name="username" type="text" id="username" value="<? echo "{$_SESSION['username']}"; ?>">
<div class="text">Password:</div><input name="pin" type="password" id="pin" class="invulbalkje"><br />
<div class="text">New Password:</div><input name="newpassword" type="password" id="newpassword" class="invulbalkje"><br />
<div class="text">Repeat New Password:</div><input name="repeatnewpassword" type="password" id="repeatnewpassword" class="invulbalkje"><br />
<input type="submit" name="Submit" value="Change" class="button">
</form>
这里是 php 的变化。(changepw.php)
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
include 'db.php';
$username = $_POST['username'];
$pin = $_POST['pin'];
$newpassword = $_POST['newpassword'];
$repeatnewpassword = $_POST['repeatnewpassword'];
$encrypted_password=md5($pin);
$encrypted_newpassword=md5($newpassword);
$result = mysql_query("SELECT pin FROM $wtbusers WHERE username='$username' and pin = '$pin'");
if(!$result)
{
echo"<script>alert('Please Fill Form Correctly')</script>"; }
if(mysql_num_rows($result)){
if($newpassword==$repeatnewpassword){
$sql=mysql_query("UPDATE $wtbusers SET pin='$pin' where username='$username'");
if($sql)
{
header("location:success.php");
}
else
{
header("location:error3.php");
}
} else {
header("location:error_password_not_matched.php");
}
} else {
echo"<script>alert('Please Fill Form Correctly')</script>";
}
?>
如果您发现问题,请与我联系。对此我将不胜感激!
请注意,您尚未创建名为 $wtbusers.
的变量$wtbusers = 'users
'; //这应该被定义(将其更改为您的任何 table 名称)
试试下面的代码。
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
include 'db.php';
// print_r($_POST);
if (isset($_POST['username'])) {
$username = $_POST['username'];
}
if (isset($_POST['pin'])) {
$pin = $_POST['pin'];
}
if (isset($_POST['newpassword'])) {
$newpassword = $_POST['newpassword'];
}
if (isset($_POST['repeatnewpassword'])) {
$repeatnewpassword = $_POST['repeatnewpassword'];
}
$encrypted_password = md5($pin);
$encrypted_newpassword = md5($newpassword);
$wtbusers = '`users`'; //this should be defined (change this to your whatever table name)
$result = mysql_query("SELECT pin FROM $wtbusers WHERE username='$username' and pin = '$pin'");
if (!$result) {
echo "<script>alert('Please Fill Form Correctly')</script>";
}
if (mysql_num_rows($result) != 0) {
if ($newpassword == $repeatnewpassword) {
$sql = mysql_query("UPDATE $wtbusers SET pin='$pin' where username='$username'");
if ($sql) {
header("location:success.php");
}
else {
header("location:error3.php");
}
}
else {
header("location:error_password_not_matched.php");
}
}
else {
echo "<script>alert('Please Fill Form Correctly')</script>";
}