21,886
社区成员
发帖
与我相关
我的任务
分享
<?php
session_start();
include("global.php");
include("conn.php");
$id=$_GET['id'];
$sql="select * from `user` where `id`='$id'";
//要先连接数据库
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
//选择数据库
$db_selected = mysql_select_db('yourdatabase', $link);
$rs=mysql_query($sql);
$row=mysql_fetch_array($rs);
$user=$row[user];
if(isset($_POST[btn1])){
$pwd=$_POST[pwd];
$sql="update `user` set `pwd`='$pwd' where `id`='$id'";
$rs=mysql_query($sql);
echo "<script>alert('修改成功!');location.href='user_list.php';</script>";
}
?>
<html>
<head>
<title></title>
</head>
<script language="javascript">
function check(){
if(document.edit_pass.pwd.value==""){
alert("密码不能为空!");
document.edit_pass.pwd.focus();
return false;
}
if(document.edit_pass.repwd.value==""){
alert("请在输一次密码!");
document.edit_pass.repwd.focus();
return false;
}
if(document.edit_pass.pwd.value!=document.edit_pass.repwd.value){
alert("两次密码输入不一致!");
document.edit_pass.repwd.focus();
return false;
}
}
</script>
<body>
<div class="top"><b>修改密码</b></div>
<center>
<table border="1">
<tr>
<td>用户名</td>
<td><?php echo $user?></td>
</tr>
<form method="post" action="edit_pass.php" name="edit_pass" onsubmit="return check()">
<tr>
<td>新密码</td>
<td><input type="text" name="pwd" size="30"></td>
</tr>
<tr>
<td>重输密码</td>
<td><input type="text" name="repwd" size="30"></td>
</tr>
<tr align="center">
<td colspan="2"><input type="submit" name="btn1" value="修改"> <input type="reset" name="btn2" value="取消"></td>
</tr>
</table>
</center>
</form>
</body>
</html>
?>