form.html
new_post.php
header("Content-type;text/html;charset=utf-8");
$_POST['title'] = empty($_POST['title']) ? '' : $_POST['title'];
$_POST['content'] = empty($_POST['content']) ? '' : $_POST['content'];
$title=$_POST['title'];
$content=$_POST['content'];
$time=date("Y-m-d H:i:s");
$conn = mysqli_connect('localhost','root','root','new','30');
mysqli_set_charset($conn,'utf8');
if($conn){
$sql="insert into news(title,content,cre_time) VALUES('$title','$content','$time')";
$que=mysqli_query($conn,$sql);//执行sql语句
if($que){
echo "";
}else{
die("数据库连接失败".mysqli_connect_error());
}
}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
数据插不进数据库,有很多种情况哦,有没有报错信息呢,如果没有的话,就断点调试找问题!
打印下$sql语句观察。