我的网站上有一个允许用户更改密码的页面
表格要求输入用户名,当前密码,新密码,确认新密码。
如果用户输入脚本弹出的所有信息,请填写正确的表格
并显示错误消息
(注意:未定义的变量:wtbusers in 第16行的/ home / www / hostname / dr / filename
警告:mysql_num_rows():提供的参数不是有效的MySQL 第20行/ home / www / hostname / dr / filename中的结果资源
我的代码粘贴在下面,如果有人可以提供帮助,我将不胜感激!谢谢!
蒂娜
更改密码信息屏幕:
<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>";
}
?>
如果您发现问题,请与我联系。我将非常感激!
答案 0 :(得分:0)
通知您尚未创建名为 $ wtbusers 的变量。
$ wtbusers =&#39; users
&#39 ;; //应该定义(将其更改为您的任何表名)
请尝试以下代码。
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>";
}