如何将一个post_id插入到mysql数据库 [英] How do I insert an post_id into a mysql database

查看:403
本文介绍了如何将一个post_id插入到mysql数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个注释系统,应该输入一个id,一个idea_id,一个user_id,一个注释,数据和时间。一切似乎工作,除非每次我发表的意见idea_id总是0.一个想法基本上是一个职位。

I have a comment system that should input an id, an idea_id, a user_id, a comment, the data, and the time. Everything seems to work except every time I post a comment the idea_id is always 0. By the way an idea is basically a post.

我这样使用:

<?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> 


推荐答案

您应该定义 $

you should define the $idea_id in your form and then pass it to your form

 $idea_id = "your_idea_id";  
 <input type = 'hidden' name = 'idea_id' value = '<?php echo $idea_id;?>' />

如果您想要查看是否有效,请尝试使用任何数字

if you wanna see if it works , just try with any number like that

  <input type = 'hidden' name = 'idea_id' value = '66' />

这篇关于如何将一个post_id插入到mysql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆