添加界面
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>发布新闻</title> </head> <body> <center><h1>发布新闻</h1></center> <form action="tianjiachuli.php" method="post"> <table width="100%" border="0" cellpadding="2" cellspacing="2"> <tr> <td></td> <td><input type="hidden" name="id" /></td> </tr> <tr> <td align="right">标题:</td> <td><input type="text" name="title" /></td> </tr> <tr> <td align="right">作者:</td> <td><input type="text" name="author" /></td> </tr> <tr> <td align="right">来源:</td> <td><input type="text" name="source" /></td> </tr> <td align="right">内容:</td> <td><textarea cols="140" rows="5" name="content"></textarea></td> </tr> <tr> <td></td> <td><input type="hidden" name="time" /></td> </tr> </table> <div><input type="submit" value="提交" /></div> </form> <div><a href="biaoge.php"><input type="submit" value="查看" /></a></div> </body> </html>
<?php $id=$_POST["id"]; $title=$_POST["title"]; $author=$_POST["author"]; $source=$_POST["source"]; $content=$_POST["content"]; $time=$_POST["time"]; include("dbda.class.php"); $db=new dbda(); $t=date(‘Y-m-d H:i:s‘); $sql="insert into news values(‘{$id}‘,‘{$title}‘,‘{$author}‘,‘{$source}‘,‘{$content}‘,‘{$t}‘)"; $r=$db->Query($sql,0,"newssystem"); if($r) { header("location:xiti.php"); } else { echo "修改失败"; }
查询界面
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>无标题文档</title> </head> <body> <table width="100%" border="1" cellpadding="0" cellspacing="0"> <tr> <td>id</td> <td>title</td> <td>author</td> <td>source</td> <td>time</td> <td>delete</td> <td>update</td> </tr> <?php include("dbda.class.php"); $db=new dbda(); $sql="select id,title,author,source,time from news "; $attr=$db->Query($sql,1,"newssystem"); foreach($attr as $v) { echo"<tr> <td>{$v[0]}</td> <td>{$v[1]}</td> <td>{$v[2]}</td> <td>{$v[3]}</td> <td>{$v[4]}</td> <td><a href=‘shanchuchuli.php?id={$v[0]}‘>delete</a></td> <td><a href=‘xiugaichuli.php?id={$v[0]}‘>update</a></td> </tr>"; } ?> </table> <a href="xiti.php">返回</a> </body> </html>
删除处理
<?php $id=$_GET["id"]; include("dbda.class.php"); $db=new dbda(); $sql="delete from news where id=‘{$id}‘"; $a=$db->Query($sql,0,"newssystem"); if($a) { header("location:biaoge.php"); } else { echo"删除失败"; }
修改界面
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>发布新闻</title> </head> <body> <center><h1>发布新闻</h1></center> <?php $id=$_GET["id"]; $db=new MYSQLi("localhost","root","","newssystem"); $sql="select * from news where id=‘{$id}‘"; $result=$db->query($sql); $attr=$result->fetch_row(); ?> <form action="xiugai.php" method="post"> <table width="100%" border="0" cellpadding="2" cellspacing="2"> <tr> <td></td> <td><input type="hidden" name="id" value="<?php echo $attr[0] ?>" /></td> </tr> <tr> <td align="right">标题:</td> <td><input type="text" name="title" value="<?php echo $attr[1] ?>" /></td> </tr> <tr> <td align="right">作者:</td> <td><input type="text" name="author" value="<?php echo $attr[2] ?>" /></td> </tr> <tr> <td align="right">来源:</td> <td><input type="text" name="source" value="<?php echo $attr[3] ?>" /></td> </tr> <td align="right">内容:</td> <td><textarea cols="140" rows="5" name="content" value="<?php echo $attr[4] ?>"></textarea></td> </tr> <tr> <td></td> <td><input type="hidden" name="time" value="<?php echo $attr[5] ?>" /></td> </tr> </table> <div><input type="submit" value="修改" /></div> </form> <div><a href="biaoge.php"><input type="submit" value="查看" /></a></div> </body> </html>
<?php $id=$_POST["id"]; $title=$_POST["title"]; $author=$_POST["author"]; $source=$_POST["source"]; $content=$_POST["content"]; $time=$_POST["time"]; include("dbda.class.php"); $db=new dbda(); $t=date(‘Y-m-d H:i:s‘); $sql="update news set title=‘{$title}‘,author=‘{$author}‘,source=‘{$source}‘,time=‘{$t}‘ where id=‘{$id}‘"; $r=$db->Query($sql,0,"newssystem"); if($r) { header("location:xiti.php"); } else { echo "添加失败"; }
时间: 2024-11-15 04:41:54