程序修改密码失败,还是老样子,哪里错了?

cph1737 2010-07-20 01:00:32
<?php
session_start();
include("global.php");
include("conn.php");
$id=$_GET['id'];
$sql="select * from `user` where `id`='$id'";
$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>
这个程序是用来修改密码的,为什么不能修改密码,哪里错了,请各位高手相助!
...全文
49 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
cph1737 2010-07-20
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 kyzy_yy_pm 的回复:]
echo update `user` set `pwd`='$pwd' where `id`='$id';
输出的是什么
[/Quote]
echo 出来没有传ID,在form中加一个隐藏域,在传ID就OK了
amani11 2010-07-20
  • 打赏
  • 举报
回复
<form method="post" action="edit_pass.php" name="edit_pass" onsubmit="return check()">


改成

<form method="post" action="edit_pass.php?id=<?php echo $id;?>" name="edit_pass" onsubmit="return check()">

试试
CunningBoy 2010-07-20
  • 打赏
  • 举报
回复
<?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>
?>
总哈哈 2010-07-20
  • 打赏
  • 举报
回复
楼主,你的有些代码级别停留在php4,请买一本php5的书好好的看一下。
$sql="update `user` set `pwd`='$pwd' where `id`='$id'";
echo "///" . $sql . "///";
$rs=mysql_query($sql);
请把///这里的语句贴出来看看!///
kyzy_yy_pm 2010-07-20
  • 打赏
  • 举报
回复
echo update `user` set `pwd`='$pwd' where `id`='$id';
输出的是什么

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧