php MYSQL 数据更新修改不了
能添加删除读取就是不能修改;提示是修改成功,但库还是没变,是什么原因?代码如下;list.html<?phperror_reporting(E_ALL&~E_NOTICE...
能添加 删除 读取 就是不能修改;提示是修改成功,但库还是没变,是什么原因?代码如下;
list.html
<?php
error_reporting(E_ALL & ~E_NOTICE);
include "conn.php";
mysql_query('set names gb2312');
$exec= "select * from user order by id desc";
$result = mysql_query($exec);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<table width="800" border="0" align="center">
<tr>
<td width="63">ID</td>
<td width="195">姓名</td>
<td width="129">性别</td>
<td width="129">密码</td>
<td width="129">备注</td>
<td width="129">操作</td>
</tr>
<?php
while($rs=mysql_fetch_object($result))
{
?>
<form action="list3.php" method="post">
<tr>
<td><?php echo $rs->id ?><input name="hiddenField" type="hidden" value="<?php echo $rs->id ?>" /></td>
<td><input name="name" type="text" id="name" value="<?php echo $rs->name ?>" /></td>
<td><input name="sex" id="sex" type="text" value="<?php echo $rs->sex?>" /></td>
<td><input name="password" id="password" type="text" value="<?php echo $rs->password ?>" /></td>
<td><input name="bz" id="bz" type="text" value="<?php echo $rs->bz ?>" /></td>
<td><input type="submit" name="Submit" value="修改" /></td>
</tr></form>
<?php } ?>
</table>
</body>
</html>
list3.php
<?php
include "conn.php";
$mid = $_POST['hiddenField'];
$name = $_POST['name'];
$sex = $_POST['sex'];
$password = $_POST['password'];
$bz = $_POST['bz'];
$sql = "update user name ='$name',sex='$sex',password='$password',bz='$bz' where id='$mid'";
$result = mysql_query($sql);
if($result)
{
echo "成功";
}
else
{
echo (mysql_error());
}
//die($sql);
?>
低级错误 感谢各位了 分就给先回答的 展开
list.html
<?php
error_reporting(E_ALL & ~E_NOTICE);
include "conn.php";
mysql_query('set names gb2312');
$exec= "select * from user order by id desc";
$result = mysql_query($exec);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<table width="800" border="0" align="center">
<tr>
<td width="63">ID</td>
<td width="195">姓名</td>
<td width="129">性别</td>
<td width="129">密码</td>
<td width="129">备注</td>
<td width="129">操作</td>
</tr>
<?php
while($rs=mysql_fetch_object($result))
{
?>
<form action="list3.php" method="post">
<tr>
<td><?php echo $rs->id ?><input name="hiddenField" type="hidden" value="<?php echo $rs->id ?>" /></td>
<td><input name="name" type="text" id="name" value="<?php echo $rs->name ?>" /></td>
<td><input name="sex" id="sex" type="text" value="<?php echo $rs->sex?>" /></td>
<td><input name="password" id="password" type="text" value="<?php echo $rs->password ?>" /></td>
<td><input name="bz" id="bz" type="text" value="<?php echo $rs->bz ?>" /></td>
<td><input type="submit" name="Submit" value="修改" /></td>
</tr></form>
<?php } ?>
</table>
</body>
</html>
list3.php
<?php
include "conn.php";
$mid = $_POST['hiddenField'];
$name = $_POST['name'];
$sex = $_POST['sex'];
$password = $_POST['password'];
$bz = $_POST['bz'];
$sql = "update user name ='$name',sex='$sex',password='$password',bz='$bz' where id='$mid'";
$result = mysql_query($sql);
if($result)
{
echo "成功";
}
else
{
echo (mysql_error());
}
//die($sql);
?>
低级错误 感谢各位了 分就给先回答的 展开
4个回答
展开全部
SQL语句写错了,
改成这样子
$sql = "update user set name =".$name.",sex=".$sex.",password=".$password.",bz=".$bz." where id=".$mid.";
应该就可以了!!
你变量放在单引号里,PHP是不解析单引号里的变量的!
改成这样子
$sql = "update user set name =".$name.",sex=".$sex.",password=".$password.",bz=".$bz." where id=".$mid.";
应该就可以了!!
你变量放在单引号里,PHP是不解析单引号里的变量的!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
那个更新的语句有问题啊,应该写成:
update user set name ='$name',sex='$sex',password='$password',bz='$bz' where id=$mid
update user set name ='$name',sex='$sex',password='$password',bz='$bz' where id=$mid
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我记得语句好像是update database.table set xxx='xxx' , yyy='yyy' where id='$id'
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
$sql = "update user SET name ='$name',sex='$sex',password='$password',bz='$bz' where id='$mid'";
SQL语句的问题
SQL语句的问题
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询