意外的列'消息'在'字段列表'

时间:2013-03-27 11:49:21

标签: php mysql

我正在尝试创建一个PHP论坛页面使用会话。每当我尝试发表评论时,我都会遇到同样的错误,不知道我在哪里出错

这是我的表格代码:

session_start();

if(!isset($_SESSION['user_id'])){

    require('login_tools.php');

    load();

    }

    $page_title = 'Post Message';

    include('includes/header.html');

    echo "<h1>Home</h1>

        <p>You are now logged in, {$_SESSION['first_name']} 

{$_SESSION['last_name']}

        </p>";

    echo '<form action = "post_action.php" method = "POST" accept-charset = "utf-8">
        <p>Subject:<br/>

        <input name = "subject" type = "text" size = "64"</p>`

        <p>Message:<br/>

        <textarea name = "message" rows = "5" cols = "50">

        </textarea></p>

        <p><input type = "submit" value = "Submit"></p>

        </form>';

以下是帖子操作的代码:

session_start();
    require('login_tools.php');


    if(!isset($_SESSION['user_id'])){

    load();
    }

    $page_title = 'Post Error';

    include('includes/header.html');

    echo '<div id = "content">';

    if($_SERVER['REQUEST_METHOD']=='POST'){

        if(empty($_POST["subject"])){

            echo '<p class = "main">Please enter a subject for this post</p>';
            }

        if(empty($_POST["message"])){

            echo '<p class = "main">Please enter a message for this 

';                 }

            if(!empty($_POST['subject']) && !empty($_POST['message'])){

                require('../connect_db.php');

                $q = "INSERT INTO forum
                    (first_name,last_name,subject,messsage,post_date)

                    VALUES(

                    '{$_SESSION[first_name]}',

                    '{$_SESSION[last_name]}',

                    '{$_POST[subject]}',

                    '{$_POST[message]}',

                    NOW())";

                    $r = mysqli_query($dbc,$q);

                        if(mysqli_affected_rows($dbc)!=1){

                            echo '<p>Error</p>'.mysqli_error($dbc);
                            }
                            else{
                                load('forum.php');
                                }

                    mysqli_close($dbc);
                    }
        }

2 个答案:

答案 0 :(得分:2)

拼写错误

 $q = "INSERT INTO forum
                    (first_name,last_name,subject,messsage,post_date)

应为message

答案 1 :(得分:0)

生成SQL的PHP​​语句缺少$ _SESSION成员名称周围的引号。

我会写

$q = "INSERT INTO forum
          (first_name,last_name,subject,messsage,post_date)

          VALUES('" .

              $_SESSION['first_name'] . "','" .

              $_SESSION['last_name'] . "','" .

              $_POST['subject'] . "','" .

              $_POST['message'] . "'," .

              "NOW())";