留言板 出错了 就是找不到错误在哪里 头痛
学海无涯
学海无涯 2018-02-10 17:20:22
[PHP讨论组]

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了


学海无涯
学海无涯

全部回复(5)
似火年华

你确定你的sql语句没有写错么   $sql="insert into message(id,user,title,content,lastdate)values('','$user','$title','$content',now())";

values(" 这里错了吧

Sven.He

你这样写肯定会到else的。 不提交 ,$_POST['submit'] 肯定没有内容。 

PHP中文网

是添加失败吗????你看下  SQL语句    单引号是不解析变量的   其它的暂时没能从代码上看得出来

学海无涯

有大神帮忙看下么

  • 回复 断点打印是排查错误最有效的办法之一
    徐金龙 作者 2018-03-06 09:55:09
韦小宝

是直接就提示失败了是么?

  • 回复 是的 是的
    学海无涯 作者 2018-02-10 18:00:28
  • 回复 你看看你获取数据获取到了么
    韦小宝 作者 2018-02-11 09:09:08
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号