<?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="修改">&nbsp;&nbsp;<input type="reset" name="btn2" value="取消"></td>
</tr>
</table>
</center>
</form>
</body>
</html>
这个程序是用来修改密码的,为什么不能修改密码,哪里错了,请各位高手相助!

解决方案 »

  1.   

    echo update `user` set `pwd`='$pwd' where `id`='$id';
    输出的是什么
      

  2.   

    楼主,你的有些代码级别停留在php4,请买一本php5的书好好的看一下。
    $sql="update `user` set `pwd`='$pwd' where `id`='$id'";
    echo "///" . $sql . "///"; 
    $rs=mysql_query($sql);
    请把///这里的语句贴出来看看!///
      

  3.   

    <?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="修改">&nbsp;&nbsp;<input type="reset" name="btn2" value="取消"></td>
    </tr></table>
    </center>
    </form>
    </body>
    </html>
    ?>
      

  4.   

    <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()">试试
      

  5.   

    echo 出来没有传ID,在form中加一个隐藏域,在传ID就OK了