Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP函数错误,未更新密码,但收到ok消息_Php_Html_Mysql - Fatal编程技术网

PHP函数错误,未更新密码,但收到ok消息

PHP函数错误,未更新密码,但收到ok消息,php,html,mysql,Php,Html,Mysql,我正在尝试更改登录用户的密码。页面上显示密码已更改,但没有更改,数据库上也没有更改,根本没有更改。我尝试使用新密码登录,但只剩下旧密码登录。我确实刷新了页面和所有内容。我试了几天,不知道是否有人会发现我的错误。今晚我想可能是因为数据库中的密码是用md5加密的。如果我已经尝试了一些事情,但没有成功,我将如何继续 error_reporting(E_ALL); ini_set("display_errors","On"); <?php include "includes/connection.

我正在尝试更改登录用户的密码。页面上显示密码已更改,但没有更改,数据库上也没有更改,根本没有更改。我尝试使用新密码登录,但只剩下旧密码登录。我确实刷新了页面和所有内容。我试了几天,不知道是否有人会发现我的错误。今晚我想可能是因为数据库中的密码是用md5加密的。如果我已经尝试了一些事情,但没有成功,我将如何继续

error_reporting(E_ALL); ini_set("display_errors","On");
<?php include "includes/connection.php" ?>
<?php
session_start();

if(@$_REQUEST["Submit"]=="Update")
{
$sql="update users set password ='$_REQUEST[newpassword]' where      user='$_SESSION[myusername]'";
if (!mysql_query($sql)) die('err: PROBLEM IN QUERY: '.mysql_error());
header("Location:changpass.php?msg=updated");
}
else
die('err: PROBLEM IN REQUEST');

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Change password</TITLE>
<script language="javascript" type="text/javascript">
function validate()
{

var formName=document.frm;

if(formName.newpassword.value == "")
{
document.getElementById("newpassword_label").innerHTML='Please Enter New Password';
formName.newpassword.focus();
return false;
}
else
{
document.getElementById("newpassword_label").innerHTML='';
}


if(formName.cpassword.value == "")
{
document.getElementById("cpassword_label").innerHTML='Enter ConfirmPassword';
formName.cpassword.focus();
return false;
}
else
{
document.getElementById("cpassword_label").innerHTML='';
}


if(formName.newpassword.value != formName.cpassword.value)
{
document.getElementById("cpassword_label").innerHTML='Passwords Missmatch';
formName.cpassword.focus()
return false;
}
else
{
document.getElementById("cpassword_label").innerHTML='';
}
}
</script>
<style type="text/css">
<!--
.style1 {font-weight: bold}
.style7 {
color: yellow;
font-size: 24px;
}
.style9 {
color: #FF6666;
font-weight: bold;
}
.style12 {
color: #666666;
font-weight: bold;
}
.style14 {color: #CC0033; font-weight: bold; }
-->
</style>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
</HEAD>
<BODY>

<form action="changpass.php" method="post" name="frm" id="frm" onSubmit="return   validate();">
<table width="47%" border="1" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2" align="center"></td>
</tr>
<tr bgcolor="#666666">
<td colspan="2"><span class="style7">Change Password</span></td>
</tr>
<?php if(isset($_REQUEST['msg']) && $_REQUEST['msg'] == 'updated') { ?>
<tr bgcolor="#666666">
<td colspan="2"><span class="style7">Password has been changed successfully.</span></td>
</tr>
<?php } ?>
<tr>
<td bgcolor="#CCCCCC"><span class="style14">New Password:</span></td>
<td bgcolor="#CCCCCC"><input type="password" name="newpassword" id="newpassword"    size="20" autocomplete="off"/>&nbsp; <label id="newpassword_label" 

class="level_msg"></td>
</tr>
<tr> 
<td bgcolor="#CCCCCC"><span class="style14">Confirm Password:</span></td>
<td bgcolor="#CCCCCC"><input type="password" name="cpassword" id="cpassword" size="20"  autocomplete="off">&nbsp; <label id="cpassword_label" 

class="level_msg"></td>
</tr><tr bgcolor="#666666"><td colspan="2" align="center"><input type="submit"   name="Submit" value="Update" /></td>
</tr></table><a href="index.php">Home</a></form></BODY></HTML>`
我增强了您的代码:

<?php
    if ($_REQUEST['Submit'] == "Update")
    {
        $sql = "UPDATE `users` SET `password`='".$_REQUEST['newpassword']."' WHERE `user`='".$_SESSION['myusername']."'";
        mysql_query($sql);
        header("Location: changpass.php?msg=updated");
        exit;
    }
?>
更新:调试步骤1

将php文件中的代码更改为此,并告诉我们是否显示任何错误消息

if(@$_REQUEST["Submit"]=="Update")
{
    $sql="update users set password ='$_REQUEST[newpassword]' where     user='$_SESSION[myusername]'";
    if (!mysql_query($sql)) die('err: PROBLEM IN QUERY: '.mysql_error());
    header("Location:changpass.php?msg=updated");
}
else
    die('err: PROBLEM IN REQUEST');

我认为您应该使用$\u GET而不是$\u REQUESTCheck mysql\u error。此外,您还可能在这方面进行mysql注入code@Blauesocke好点,他可能应该看看这个:不管你是否会解决这个问题,考虑使用PDO或MySQL来准备未来的陈述。您的mysql代码不安全。如果您仍然想坚持使用mysql,那么您甚至没有使用mysql\u real\u escape\u字符串进行保护。尝试编写如下SQL语句:mysql_querySELECT id FROM table WHERE name='.myqsl_real_escape_string$name'.…关于安全性的好建议,我很感兴趣,但我会坚持使用这段代码,因为我已经花了很多时间。而且,在未来,我将努力学习PDO-
if(@$_REQUEST["Submit"]=="Update")
{
    $sql="update users set password ='$_REQUEST[newpassword]' where     user='$_SESSION[myusername]'";
    if (!mysql_query($sql)) die('err: PROBLEM IN QUERY: '.mysql_error());
    header("Location:changpass.php?msg=updated");
}
else
    die('err: PROBLEM IN REQUEST');