Maison > Article > développement back-end > php修改数据库出现问题
<form action="guanli_ok.php" method="post" enctype="multipart/form-data" name="form2" id="form2"> <table width="527" height="282" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="194" height="46"><div align="left"><?php echo $_SESSION['user'];?> 用户信息修改</div></td> <td width="333"><div align="left"></div></td> </tr> <tr> <td height="46"><div align="right">用户名:</div></td> <td><div align="left"><input type="text" id="user" readonly="readonly" value="<?php echo $_SESSION['user'];?>"/></div></td> </tr> <tr> <td height="40"><div align="right">原密码:</div></td> <td><div align="left"><input type="text" id="pwd" /></div></td> </tr> <tr> <td height="30"><div align="right">新密码:</div></td> <td><div align="left"><input type="text" id="xpwd" /></div></td> </tr> <tr> <td height="30"><div align="right">确认密码:</div></td> <td><div align="left"><input type="text" id="quren" /></div></td> </tr> <tr> <td height="30"><div align="right">部门:</div></td> <td><div align="left"><input type="text" id="section" /></div></td> </tr> <tr> <td height="30"><div align="right">真实姓名:</div></td> <td><div align="left"><input type="text" id="name" /></div></td> </tr> <tr> <td height="30"> </td> <td><input type="submit" id="xiugai" value="确认修改"/> </td> </tr> </table> </form>
<?php header("content-type:text/html;charset=utf-8"); //设置文件编码include("conn/conn.php"); //包含数据库连接文件if(isset($_POST['Submit']) and $_POST['Submit']=="提交"){ //判断提交按钮是否存在 $user=$_POST['user']; //定义用户名变量 $pwd=$_POST['pwd']; //定义原密码变量 $xpwd=$_POST['xpwd']; //定义新密码 $section=$_POST['section']; //定义定义部门 $name=$_POST['name']; //定义真实姓名 $insert=mysql_query("update tb_book set pwd='$xpwd',section='$section',name='$section' where id='$user' pwd='pwd'",$conn); //执行更新操作 echo mysql_error(); if($insert){ //判断更新语句是否执行成功 echo "<script>alert('修改成功!');window.location.href='index.php'</script>"; //输出更新成功提示 } else{ echo "<script>alert('修改失败!');window.location.href='insert.php'</script>"; //输出更新失败提示 }}?>
SQL 串写错了
$insert=mysql_query("update tb_book set pwd='$xpwd',section='$section',name='$section' where id='$user' AND pwd='pwd'",$conn);
改了之后还是没反应,,,
SQL 串写错了
$insert=mysql_query("update tb_book set pwd='$xpwd',section='$section',name='$section' where id='$user' AND pwd='pwd'",$conn);
请你打开 php 的错误显示功能
请你打开 php 的错误显示功能
开启了 但是还是空白一片
<p class="yy"> <p class="yy"> <p class="yy"> <td><input type="submit" id="xiugai" value="确认修改"/> </td> if(isset($_POST['Submit']) and $_POST['Submit']=="提交"){ 不用解释了吧。。。 </p>已改 但是还是空白。,。 </p> 你没进if if(isset($_POST['xiugai']) and $_POST['xiugai']=="确认修改"){ </p> ...
php.ini 中
display_errors = On
重启 web 服务器
你的错误实际产生于 conn/conn.php
如果你的错误显示是打开的话
$insert=mysql_query("update tb_book set pwd='$xpwd',section='$section',name='$section' where id='$user' pwd='pwd'",$conn); //执行更新操作
echo mysql_error(); //这里一定是有输出的,因为 sql 指令错了
conn
<?php$conn=mysql_connect("localhost","root",""); //连接数据库服务器mysql_select_db("db_book",$conn); //连接数据库mysql_query("set names utf8"); //对数据库中编码格式进行转换,避免出现中文乱码的问题?>
Object not found!
The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.
If you think this is a server error, please contact the webmaster.
Error 404
localhost
06/30/15 13:38:48
Apache/2.2.9 (APMServ) mod_ssl/2.2.9 OpenSSL/0.9.8h PHP/5.2.6
Object not found!
The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.
If you think this is a server error, please contact the webmaster.
Error 404
localhost
06/30/15 13:38:48
Apache/2.2.9 (APMServ) mod_ssl/2.2.9 OpenSSL/0.9.8h PHP/5.2.6
Object not found!
The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.
If you think this is a server error, please contact the webmaster.
Error 404
localhost
06/30/15 13:38:48
Apache/2.2.9 (APMServ) mod_ssl/2.2.9 OpenSSL/0.9.8h PHP/5.2.6
Object not found!
The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.
If you think this is a server error, please contact the webmaster.
Error 404
localhost
06/30/15 13:38:48
Apache/2.2.9 (APMServ) mod_ssl/2.2.9 OpenSSL/0.9.8h PHP/5.2.6
php.ini 中
display_errors = On
重启 web 服务器
你的错误实际产生于 conn/conn.php
如果你的错误显示是打开的话
$insert=mysql_query("update tb_book set pwd='$xpwd',section='$section',name='$section' where id='$user' pwd='pwd'",$conn); //执行更新操作
echo mysql_error(); //这里一定是有输出的,因为 sql 指令错了
print_r($_POST); 就能发现是个空数组,怎么都不可能进入if里面。肯定为空了。
把你的form 定义改一改。
给 每个元素加上name 属性。
submit 也是一样,value改成value="提交"
改成
应该就能进入if分支了
Object not found!
The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.
If you think this is a server error, please contact the webmaster.
Error 404
localhost
06/30/15 13:38:48
Apache/2.2.9 (APMServ) mod_ssl/2.2.9 OpenSSL/0.9.8h PHP/5.2.6