php留言板更新代码
php留言板更新代码
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <?php $lianjie = mysql_connect("localhost", "root", "xiaolie") or die("连接失败"); mysql_query("set names utf8"); if ($lianjie) { mysql_select_db("xiaolie"); if (!$_GET) { $xuanbiao = "select * from zhuce"; $fasong = mysql_query($xuanbiao) or die(mysql_error()); echo "<table border=1> <tr> <td>编号</td> <td>用户名称</td> <td>性别</td> <td>年龄</td> <td>注册时间</td> <td>操作</td> </tr>"; while ($nr = mysql_fetch_array($fasong)) { echo "<tr> <td>" . $nr["id"] . "</td> <td>" . $nr["name"] . "</td> <td>" . $nr["xingbie"] . "</td> <td>" . $nr["nianling"] . "</td> <td>" . $nr["zc_shijian"] . "</td> <td><a href=gx_my.php?id=" . $nr["id"] . ">编辑</a></td> </tr>"; } echo "</table>"; } else { if (!$_POST) { $xianid = "select * from zhuce where id=" . $_GET["id"]; $fasong = mysql_query($xianid) or die(mysql_error()); $nr = mysql_fetch_array($fasong); ?> <form method=post action="gx_my.php?id=<?php echo $_GET["id"]; ?>"> <?php echo $nr["id"] . "<br>"; ?> <input type="hidden" name="id" value=<?php echo $nr["id"]; ?>> 姓名<input type="text" name="name" value=<?php echo $nr["name"]; ?>><br> 性别<input type="text" name="xingbie" value=<?php echo $nr["xingbie"]; ?>><br> 年龄<input type="text" name="nianling" value=<?php echo $nr["nianling"]; ?>><br> 注册时间<input type="text" name="zc_shijian" value=<?php echo $nr["zc_shijian"]; ?>><br> <input type="submit" name="ok" value="提交"> </form> <?php } else { $gx = "update zhuce set name='" . $_POST["name"] . "',xingbie='" . $_POST["xingbie"] . "',nianling='" . $_POST["nianling"] . "',zc_shijian='" . $_POST["zc_shijian"] . "' where id='" . $_POST["id"] . "'"; $fasong = mysql_query($gx); if ($fasong) { echo "记录已经成功修改<br><a href=gx_my.php>继续修改记录</a>"; } else { echo "记录修改失败<br><a href=gx_my.php?id=" . $_POST["id"] . ">返回</a>"; } } } }
文章网址:http://www.phprm.com/code/92e06c084701b20a260502a0e772e40d.html
随意转载^^但请附上教程地址。