这是我的insert.php<?phpheader("Content-type:text/html;charset=utf-8");//接收数据$title = $_POST['title'];$content = $_POST['content'];$addtime = date("Y-m-d H:i:s"); //2016-3-25 09:56:22//echo $addtime;//对数据进行验证if ($title == '' || $content == '') { //echo "标题或内容不能为空!"; echo "<script>alert('标题或内容不能为空!'); window.location.href='add.php';</script>"; exit;}//插入数据到数据库//1.连接数据库$conn = @mysql_connect('localhost','root','');//2.选择数据库mysql_select_db("mes");//3.设置编码mysql_query("set names utf8");//4.准备插入sql语句$sql = "insert into mes_info values('','{$title}','{$content}','{$addtime}')";//5.发送sql语句$res = mysql_query($sql);//判断是否成功if (!$res) { echo "<script>alert('添加失败!');</script>";}else{ echo "<script>alert('添加成功!'); window.location.href='index.php';</script>";}?>这是我的add.php里的form表单<form role="form" action="insert.php" method="post"> <div class="form-group"> <label>留言主题</label> <input type="text" class="form-control" name="title"> </div> <div class="form-group"> <label>留言内容</label> <textarea class="form-control" rows="10" name="content"></textarea> </div> <input type="submit" class="btn btn-default" value="发表"> </form>一直提示添加失败
添加回答
举报
0/150
提交
取消