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.
I did this using:
<?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>