PHP develops simple news release system news modification page
Earlier we introduced the implementation of the news list page and some of its functional modules
When we click "Modify" in the editing option of the news list page, Jump directly to the news modification page,
<body> <a href="edit.php?id=<?php echo $arr['id']?>"><font color="red">修改</font></a> </body>
The news modification page here is edit.php, when you click "Modify", jump to the news modification page through the id value of this news ,
Use $_GET on the news modification page to obtain the id, and display the content in the <form> form of the modification page through the database select statement for modification.
<?php $id = isset($_GET["id"])?$_GET["id"]:""; ?>
The SQL statement is as follows:
<?php $sql="select id,title,author,content from new where id = '$id'"; $rel = mysqli_query($link,$sql);//执行sql语句 $arr= mysqli_fetch_array($rel); //获取一条新闻的所有信息 ?>
Get the title, author and content through POST method
<?php $title = isset($_POST['title'])?$_POST['title']:""; //获取标题 $author = isset($_POST['author'])?$_POST['author']:""; //获取作者 $content = isset($_POST['content'])?$_POST['content']:""; //获取内容 ?>
Put the obtained content Display in HTML page
<body> <form name="article" method="post" action="update.php" style="margin:5px;"> <h1>新闻修改页</h1> <input type="hidden" name="id" value="<?php echo $arr['id']?>"/><br/> 标 题:<input type="text" name="title" value="<?php echo $arr['title']?>"/><br/><br/> 作 者:<input type="text" name="author" value="<?php echo $arr['title']?>"/><br/><br/> <span>内 容:</span> <textarea cols=30 rows=5 name="content"><?php echo $arr['content']?></textarea><br/><br/> <input type="submit" value="修改新闻"/> </form> </body>
This way, you can click "Modify" to jump to the news editing page and display the HTML page of the news content.
Full code:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>新闻修改页面</title> <style type="text/css"> span{display:inline-block; float: left; width: 50px;} input[type="submit"]{margin-left: 10%;} </style> </head> <body bgcolor="#ccc"> <?php $link = mysqli_connect('localhost','username','password','test'); mysqli_set_charset($link, "utf8"); if (!$link) { die("连接失败:".mysqli_connect_error()); } $id = isset($_GET["id"])?$_GET["id"]:""; $title = isset($_POST['title'])?$_POST['title']:""; $author = isset($_POST['author'])?$_POST['author']:""; $content = isset($_POST['content'])?$_POST['content']:""; $sql="select id,title,author,content from new where id = '$id'"; //echo $sql; $rel = mysqli_query($link,$sql);//执行sql语句 $arr= mysqli_fetch_array($rel); ?> <form name="article" method="post" action="update.php" style="margin:5px;"> <h1>新闻修改页</h1> <input type="hidden" name="id" value="<?php echo $arr['id']?>"/><br/> 标 题:<input type="text" name="title" value="<?php echo $arr['title']?>"/><br/><br/> 作 者:<input type="text" name="author" value="<?php echo $arr['title']?>"/><br/><br/> <span>内 容:</span> <textarea cols=30 rows=5 name="content"><?php echo $arr['content']?></textarea><br/><br/> <input type="submit" value="修改新闻"/> </form> </body> </html>