數(shù)據(jù)能接受到php文件中,但是就是不進(jìn)數(shù)據(jù)庫(kù)
<?php
header("Content-type:text/html;charset=utf-8");
//接收數(shù)據(jù)
$title = $_POST['title'];
$content = $_POST['content'];
$addtime = date("Y-m-d H:i:s");
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.插入sql語(yǔ)句
$sql = "INSERT into mes_info values('','{$title}','{$content}','{$addtime}')";
//5.發(fā)送sql語(yǔ)句
$res = mysql_query($sql);
//判斷是否成功
if(!$res){
echo"<script>
alert('添加失敗');
window.location.href='add.php';
</script>";
}else{
echo"<script>
alert('添加成功');
window.location.href='add.php';
</script>";
}
?>
圖片描述
html提交表單,數(shù)據(jù)不進(jìn)庫(kù),幫忙看看是不是字段搞錯(cuò)了?
喵喵時(shí)光機(jī)
2019-03-05 00:06:25