接着上次续写:
这里是 增删改查 的第三个功能 修改
代码首页
<title>新闻首页</title>
</head>
<body bgcolor="#CC6666">
<h1 align="center">新闻首页</h1>
<h3 align="center"><a href="action.html">新建新闻</a> <a href="xgxw.php">修改新闻</a> 删除新闻 <a href="ssxw.html">搜索新闻</a></h3>
</body>
点击界面
<title>修改新闻</title>
</head>
<body>
<h1>修改新闻</h1>
<table width="900" border="1" align="center">
<tr>
<th>新闻ID</th>
<th>标题</th>
<th>关键字</th>
<th>作者</th>
<th>发布时间</th>
<th>内容</th>
<th>操作</th>
</tr>
<?php
include('mysql.php');
//查询新闻
$sy="select * from news";
$cx=mysql_query($sy);
while($row=mysql_fetch_row($cx)){
echo "<tr align='center'>";
echo "<td>$row[0]</td>";
echo "<td>$row[1]</td>";
echo "<td>$row[2]</td>";
echo "<td>$row[3]</td>";
echo "<td>$row[4]</td>";
echo "<td>$row[5]</td>";
echo "<td><a href='xg.php?id={$row[0]}'>修改</a></td>";
echo "</tr>";
}
?>
</table>
</body>
修改后重新提交
<title>新闻修改</title>
</head>
<body>
<?php
include("mysql.php");
$id=$_GET['id'];
$sql="select * from news where id='$id'";
$zy=mysql_query($sql);
$sysz=mysql_fetch_row($zy);
?>
<form action="xgtj.php" method="post">
<input type="hidden" name="id" value="<?php echo $sysz[0] ?>" />
<h2 align="center">修改新闻</h2>
<hr />
<table width="500" border="2" align="center">
<tr>
<td>新闻标题</td>
<td><input type="text" name="title" value="<?php echo $sysz[1] ?>"/></td>
</tr>
<tr>
<td>关键字</td>
<td><input type="text" name="keywords" value="<?php echo $sysz[2] ?>" /></td>
</tr>
<tr>
<td>作者</td>
<td><input type="text" name="zz" value="<?php echo $sysz[3] ?>"/></td>
</tr>
<tr>
<td>新闻内容</td>
<td><input type="text" name="nr" value="<?php echo $sysz[5] ?>"/></td>
</tr>
<tr align="center">
<td colspan="2"><input type="submit" value="提交" /></td>
</tr>
</table>
</form>
</body>
提交到后台
<title>修改提交</title>
</head>
<body>
<?php
include("mysql.php");
$id=$_POST['id'];
$bt=$_POST['title'];
$gjz=$_POST['keywords'];
$zz=$_POST['zz'];
$nr=$_POST['nr'];
//修改语句
$xg="update news set title='$bt',keywords='$gjz',author='$zz',content='$nr' where id=$id";
$sy=mysql_query($xg);
header("Location:xgxw.php");
?>
</body>
还有最后一个 删除功能 敬请期待。。。
期待和你一起学习!!!