javascript - 如何使用php和mysql更改密码?

标签 javascript php mysql

嗨,我有一个 php 页面,我在其中编写了一些用于更改密码的 html 和 php 代码,当我直接在本地主机上运行此页面时,它工作正常。

但是当我将此页面包含在任何其他 html 页面中并使用时它不起作用

这是我的代码

changepassword.php

<?php
session_start();
?>
<?php
$eid=$_SESSION['eid'];
echo $eid;

$conn = mysql_connect("localhost","root","root");
mysql_select_db("helixcrm",$conn);
if(count($_POST)>0) {
$result = mysql_query("SELECT *from login WHERE eid='" . $eid . "'");
$row=mysql_fetch_array($result);


if($_POST["currentPassword"] == $row["password"]) {
mysql_query("UPDATE login set password='" . $_POST["newPassword"] . "' WHERE eid='" . $eid . "'");
$message = "Password Changed";
} else $message = "Current Password is not correct";
}
?>
<html>
<head>
<title>Change Password</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
<script>
function validatePassword() {
var currentPassword,newPassword,confirmPassword,output = true;

currentPassword = document.frmChange.currentPassword;
newPassword = document.frmChange.newPassword;
confirmPassword = document.frmChange.confirmPassword;

alert(i+j+k);

if(!currentPassword.value) {
    currentPassword.focus();
    document.getElementById("currentPassword").innerHTML = "required";
    output = false;
}
else if(!newPassword.value) {
    newPassword.focus();
    document.getElementById("newPassword").innerHTML = "required";
    output = false;
}
else if(!confirmPassword.value) {
    confirmPassword.focus();
    document.getElementById("confirmPassword").innerHTML = "required";
    output = false;
}
if(newPassword.value != confirmPassword.value) {
    newPassword.value="";
    confirmPassword.value="";
    newPassword.focus();
    document.getElementById("confirmPassword").innerHTML = "not same";
    output = false;
}   
return output;
}
</script>
</head>
<body>
<form name="frmChange" method="post" action="" onSubmit="return validatePassword()">
<div style="width:500px;">
<div class="message"><?php if(isset($message)) { echo $message; } ?></div>
<table border="0" cellpadding="10" cellspacing="0" width="500" align="center" class="tblSaveForm">
<tr class="tableheader">
<td colspan="2">Change Password</td>
</tr>
<tr>
<td width="40%"><label>Current Password</label></td>
<td width="60%"><input type="password" name="currentPassword"  id="currentpassword"class="txtField"/><span id="currentPassword"  class="required"></span></td>
</tr>
<tr>
<td><label>New Password</label></td>
<td><input type="password" name="newPassword"  id="newpassword" class="txtField"/><span id="newPassword" class="required"></span></td>
</tr>
<td><label>Confirm Password</label></td>
<td><input type="password" name="confirmPassword" id ="confirmpassword"class="txtField"/><span id="confirmPassword" class="required"></span></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="Submit" class="btnSubmit"></td>
</tr>
</table>
</div>
</form>
</body></html>

当我编写这样的代码时,此页面工作正常,但它不起作用

<script type="text/javascript">
            $(document).ready(function() {
                $("#resetpassword").click(function() {
                    $(function() {
                        $("#RightPaneContainerDiv").load("changepassword.php");
                    });
                });
            });
        </script>

重置密码

上面的代码不起作用

我怎样才能实现我的输出

提前致谢

最佳答案

您无法将完整的 html 页面加载到另一个页面的 div 中。 也许最简单的方法是使用 iframe:

$("#resetpassword").click(function() {
      $(function() {
          $("#RightPaneContainerDiv").html('<iframe class="cpassword" src="changepassword.php"></iframe>');
      });
});

使用 CSS 适当设计样式

关于javascript - 如何使用php和mysql更改密码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25747813/

相关文章:

php - 所有付款的 MYSQL 总值(value)字段

javascript - 如何使用 ImmutableJS 更新 List 中的元素?

javascript - 工具提示未显示在 d3 图表中点/圆顶部的附加 'rect' 处

php - 实体元数据包装器异常 : unknown data property for field

mysql - 从主机连接到 homestead mysql

php - Laravel 中每年都有单独的表

php - MVC php/ajax问题

javascript - 如果我有SIP帐号,如何通过PC上的浏览器调用电话?

php - 插入表单并多次上传

php - 生成唯一的上升 ID