新闻添加数据


大体思路:
根据查询数据库,打印一张表,当点击添加按钮,跳转至新闻页面进行添加,添加完成,经过新闻添加页面的处理,获取提交的值,通过MySQL语句,进行添加。

新闻页面:
<!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> <style> *{ margin-top:10px; padding:0px; } </style> </head> <body> <h3>发布新闻</h3> <form method="post" action="xwchuli.php"> <div>标题:<input type="text" name="title" style="350px;"/></div> <div class="b">作者:<input type="text" name="author" /></div> <div class="c">来源:<input type="text" name="source" /></div> <div>内容:<textarea cols="50" rows="5" name="content"></textarea></div> <div>时间:<input type="text" name="time" /></div> <div style="margin-left:80px;"><input type="submit" value="提交" /><input type="submit" value="查看" /></div> </form> </body> </html>


新闻添加处理页面:
<?php $title=$_POST["title"]; //获取form表单提交的name值 POST数组接受 $author=$_POST["author"]; $source=$_POST["source"]; $content=$_POST["content"]; $time=$_POST["time"]; $db=new MySQLi("localhost","root","","xinwen"); !mysqli_connect_error() or die("连接失败!"); $sql="insert into news values('','{$title}','{$author}','{$source}','{$content}','{$time}')"; $result=$db->query($sql); if($result) { header("location:zhuye.php"); } else { echo"失败"; } ?>

  

  

原文地址:https://www.cnblogs.com/yuchao19950412/p/5484522.html