我有一个注释系统,应该输入一个id,idea_id,一个user_id,一个注释,数据和时间。除了我每次发表评论外,所有内容似乎都可以正常工作,idea_id始终为0。

我这样做是使用:

<?php
    if(isset($_POST['submit'])) {

        $comment = $_POST['comment'];
        $user_id = $_SESSION['user_id'];
        $idea_id = $_POST['idea_id'];


        if(empty($comment)) {
            $message = "You Haven't Written Anything";
    } else {
        mysql_query("INSERT INTO comments (idea_id, user_id, comment, date, time) VALUES('".$idea_id."', '".$user_id."', '".$comment."', now(), now()) ") or die (mysql_error());
        $message = "OK! Thanks for leaving your comment!";
        if(isset($_GET['user_id'])) {
    $_SESSION['user_id'] = $_GET['user_id'];
    }

    }

        echo "<div class = 'box'>$message</div>";
    }
    ?>



<form method = 'Post'  name = 'comment_form'>

    Comment: <br/>
    <input type = 'text' name = 'comment' id = 'comment' autocomplete= 'off' />
    <input type = 'hidden' name = 'idea_id' value = '<?php echo $idea_id; ?>' />
    <input type = 'submit' name = 'submit' value = 'Comment' />
</form>

最佳答案

您似乎并没有不断统计表单中有多少个想法。

我建议您允许数据​​库为您管理idea_id,它是主键。

您的应用程序将如何处理重复的idea_id?

关于php - 如何将post_id插入mysql数据库,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21768174/

10-10 00:08
查看更多