Article adding processing page
The adding processing flow chart is as follows:
The code is as follows:
<?php require_once("../connect.php"); //把传递过来的信息入库,在入库之前对所有的信息进行校验。 if(!(isset($_POST['title'])&&(!empty($_POST['title'])))){ echo "<script>alert('标题不能为空');history.go(-1);</script>"; } $title = $_POST['title']; $author = $_POST['author']; $description = $_POST['description']; $content = $_POST['content']; $dateline = time(); $insertsql = "insert into article(title, author, description, content, dateline) values('$title', '$author', '$description', '$content', $dateline)"; //echo $insertsql; //exit; if(mysqli_query($conn,$insertsql)){ echo "<script>alert('发布文章成功');window.location.href='admin_manage.php';</script>"; }else{ echo "<script>alert('发布失败');history.go(-1);</script>"; } ?>
Code explanation
First introduce the file to connect to the database, connect to the database
Determine whether the title has been passed through the post method, if not, it will prompt that the title cannot be empty , return to the previous page, and continue if necessary
Get all the values passed in the post method, and use the timestamp method to obtain the time
Insert the obtained data into the database to determine whether it is successful. If it is not successful, it will prompt that the publication failed and return to the add page. If it is successful, it will jump to the article management page