我的网站上有一个允许用户更改密码的页面
表单要求用户名,当前密码,新密码,确认新密码。
如果用户输入了所有信息,会弹出一个脚本,请正确填写表单
和错误信息显示
(注意:未定义变量:wtbusers in/home/www/hostname/dr/filename第16行
警告:mysql_num_rows():提供的参数不是一个有效的MySQL结果资源在/home/www/hostname/dr/filename(第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>
(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
';//这应该定义(更改为您的任何表名)
试试下面的代码。
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>";
}