PHP开发留言板之留言页面

这一节讲的是第二个页面,留言页面,就是通过留言页,写数据,将数据插入数据库的一步。

<?php
session_start();
header("content-type:text/html;charset=utf-8");
//连接数据库
$link = mysqli_connect("localhost","root","root","message");
mysqli_set_charset($link,"utf8");
if (!$link) {
   die("连接失败: " . mysqli_connect_error());
}
$name = isset($_POST['name'])?$_POST['name']:"";
$title = isset($_POST['title'])?$_POST['title']:"";
$content = isset($_POST['content'])?$_POST['content']:"";
$time = date("Y-m-d H:i:s");

$sql ="insert into details(name,title,content,time) values('$name','$title','$content','$time')";
$rel = mysqli_query($link,$sql);

if($rel){
   echo"留言成功"."<br/><br/>";
   echo"<a href='list.php'>跳转至留言列表页面</a>";
}else{
   echo"留言失败"."<br/><br/>";
   echo"<a href='form.html'>跳转至留言编辑页面</a>";
}
?>
<html>
<head>
   <meta charset="utf-8" />
   <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
   <meta name="format-detection" content="telephone=no" />
   <title>留言板</title>
   <style>
.w410{
           width:410px
}
       .mr_auto{
           margin:0 auto;
}
       .w400{
           width:400px
}
   </style>
</head>
<body>
<div  class="w410 mr_auto">
<!--头部图片-->
<div>
       <img src="https://img.php.cn/upload/course/000/000/007/5816db62346b9319.jpg">
   </div>
   <div style="padding-top: 30px;" class="mr_auto w400">
       <form method="post" name="form1" id="form1" action="message.php">
标题:<input type="text" name="title"><br/><br/>
内容:<textarea style="width:350px;height:200px;" name="content"></textarea><br/><br/>
作者:<input type="text" name="name"><br/><br/>
           <a href=""><input type="submit" style="margin-left:350px" value="提交"></a>
       </form>
   </div>
   </div>
</body>
</html>


继续学习
||
<?php session_start(); header("content-type:text/html;charset=utf-8"); //连接数据库 $link = mysqli_connect("localhost","root","root","message"); mysqli_set_charset($link,"utf8"); if (!$link) { die("连接失败: " . mysqli_connect_error()); } $name = isset($_POST['name'])?$_POST['name']:""; $title = isset($_POST['title'])?$_POST['title']:""; $content = isset($_POST['content'])?$_POST['content']:""; $time = date("Y-m-d H:i:s"); $sql ="insert into details(name,title,content,time) values('$name','$title','$content','$time')"; $rel = mysqli_query($link,$sql); if($rel){ echo"留言成功"."<br/><br/>"; echo"<a href='list.php'>跳转至留言列表页面</a>"; }else{ echo"留言失败"."<br/><br/>"; echo"<a href='form.html'>跳转至留言编辑页面</a>"; } ?> <html lang="zh-CN"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"> <meta name="format-detection" content="telephone=no" /> <title>留言板</title> <style> .w410{ width:410px } .mr_auto{ margin:0 auto; } .w400{ width:400px } </style> </head> <body> <div class="w410 mr_auto"> <!--头部图片--> <div class="head"> <img class="w1200" src="http://img.php.cn/upload/course/000/000/007/5816db62346b9319.jpg"> </div> <div style="padding-top: 30px;" class="mr_auto w400"> <form method="post" name="form1" id="form1" action="message.php"> 标题:<input type="text" name="title"><br/><br/> 内容:<textarea style="width:350px;height:200px;" name="content"></textarea><br/><br/> 作者:<input type="text" name="name"><br/><br/> <a href=""><input type="submit" style="margin-left:350px" value="提交"></a> </form> </div> </div> </body> </html>
提交重置代码