Hello pls i am making a comment feature for my log.
I want the comments to be submited from a form in the "READ_MORE.PHP" , and i want the form to be processed in a "COMMENT.PHP" page were the form values are insertrd in the Comment table... (which has 5 fields - id,name,comment,post_id,date)
I already made a code for that. its working but the onlyy problem is that the post_id is not having any value its always 0. So i think it might be that i didn't get the post_id from the "READ_MORE.PHP" page...
So please someone pls help me... Below are my codes:

I have attatched the READ_MORE and COMMENT pages to this post

Thanks!!!

Recommended Answers

All 5 Replies

In comment.php, you are retrieving Post ID via $_GET[] as opposed to via $_POST[]. GET is for query strings, such as comment.php?post_id=123 while POST is for data submitted from a form such as this one.

<form method="POST" name="form" action="comment.php">

    <div class="form-group">
        <input class="form-control" type="text" id="name" name="name" placeholder="Your name..." />
    </div>
    <div class="form-group">
        <textarea name="comment" id="message" class="form-control" placeholder="Your comment..."></textarea>
    </div>
    <div class="form-group">
        <button type="submit" class="btn btn-success" name="submit">Comment</button>
    </div>

</form>

You can see here that you are passing in name and comment via POST, but you are not passing in post ID anywhere. You need to pass post ID into the form as well, preferably as a hidden input variable.

<input type="hidden" name="post_id" value="<?php echo $_GET['post_id']?>">

Thanks Uncle Dani....it worked as i inserted the hidden input variable... #HeartYA bro

Sir, one more thing.... if You look at my COMMENT.PHP page.. you'll see that i want the COMMENT.PHP page to redirect back to the READ_MORE.PHP page that carries the particular post that was just commented on.... so i used

header("Location :read_more.php");.... but its not working. its not even redirecting... it just stays in the blank COMMENT page... pls help

You cannot redirect to a different page if any HTML has already been echo'ed out to the page.

This probably isn't it, but try header("Location: read_more.php"); instead (notice the colon followed by a space).

Oh, and also, I'm a girl :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.