add.php文件内容
<?php
//导入连接数据库文件
include ('conn.php');
//检测用户是否提交按钮
if(isset($_POST['submit'])){
$id=$_POST['id'];
$user=$_POST['user'];
$title=$_POST['title'];
$content=$_POST['content'];
$sql="insert into message(id,user,title,content,lastdate)values('','$user','$title','$content',now())";
mysqli_query($conn,$sql);
// echo "<script>alert('添加成功');history.go(-1)</script>";
echo"<script>alert('留言成功');location.href='liu.html'</script>";
}else{
echo "失败";
}
?>
liu.html内容
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>第一个MYSQL查询留言本</title>
<script type="text/javascript" src="http://www.francescomalagrino.com/BootstrapPageGenerator/3/js/jquery-2.0.0.min.js"></script>
<script type="text/javascript" src="http://www.francescomalagrino.com/BootstrapPageGenerator/3/js/jquery-ui"></script>
<link href="http://www.francescomalagrino.com/BootstrapPageGenerator/3/css/bootstrap-combined.min.css" rel="stylesheet" media="screen">
<script type="text/javascript" src="http://www.francescomalagrino.com/BootstrapPageGenerator/3/js/bootstrap.min.js"></script>
<?php include ("add.php")?>
</head>
<body>
<?php include ("add.php")?>
<div class="container-fluid">
<div class="row-fluid">
<div class="span12">
<div class="page-header">
<h1>
第一个MYSQL查询留言本 <small>V1.0</small>
</h1>
</div>
<div class="hero-unit">
<h1>
Hello, world!
</h1>
<p>
这是一个可视化布局模板, 你可以点击模板里的文字进行修改, 也可以通过点击弹出的编辑框进行富文本修改. 拖动区块能实现排序.
</p>
<p>
<a class="btn btn-primary btn-large" href="#">参看更多 »</a>
</p>
</div>
<table class="table table-bordered">
<thead>
<tr>
<th>
ID
</th>
<th>
名字
</th>
<th>
标题
</th>
<th>
内容
</th>
</tr>
</thead>
<tbody>
<tr class="success">
<td>
ID
</td>
<td>
TB - Monthly
</td>
<td>
01/04/2012
</td>
<td>
Approved
</td>
</tr>
</tbody>
</table>
<form action="add.php" method="post">
<fieldset>
<legend>表单项</legend>
<label>名字</label><input type="text" name="user" required/>
<label>标题</label><input type="text" name="title" required/>
<label>留言内容</label><textarea name="content" rows="5" cols="30"></textarea>
<hr>
<button type="submit" class="btn" name="submith">提交</button>
</fieldset>
</form>
</div>
</div>
</div>
</body>
</html>
问题 : 没错提交 感觉都没走if 就到else了
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
你确定你的sql语句没有写错么 $sql="insert into message(id,user,title,content,lastdate)values('','$user','$title','$content',now())";
values(" 这里错了吧
你这样写肯定会到else的。 不提交 ,$_POST['submit'] 肯定没有内容。
是添加失败吗????你看下 SQL语句 单引号是不解析变量的 其它的暂时没能从代码上看得出来
有大神帮忙看下么
是直接就提示失败了是么?