這是我的insert.php<?phpheader("Content-type:text/html;charset=utf-8");//接收數(shù)據(jù)$title = $_POST['title'];$content = $_POST['content'];$addtime = date("Y-m-d H:i:s"); ? //2016-3-25 09:56:22//echo $addtime;//對(duì)數(shù)據(jù)進(jìn)行驗(yàn)證if ($title == '' || $content == '') { //echo "標(biāo)題或內(nèi)容不能為空!"; echo "<script>alert('標(biāo)題或內(nèi)容不能為空!'); window.location.href='add.php';</script>"; exit;}//插入數(shù)據(jù)到數(shù)據(jù)庫(kù)//1.連接數(shù)據(jù)庫(kù)$conn = @mysql_connect('localhost','root','');//2.選擇數(shù)據(jù)庫(kù)mysql_select_db("mes");//3.設(shè)置編碼mysql_query("set names utf8");//4.準(zhǔn)備插入sql語(yǔ)句$sql = "insert into mes_info values('','{$title}','{$content}','{$addtime}')";//5.發(fā)送sql語(yǔ)句$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>留言內(nèi)容</label> <textarea class="form-control" rows="10" name="content"></textarea> </div> ? <input type="submit" class="btn btn-default" value="發(fā)表"> </form>一直提示添加失敗
- 1 回答
- 0 關(guān)注
- 932 瀏覽
添加回答
舉報(bào)
0/150
提交
取消