0

I'm having some difficulty with php forms.

I have created a page called 'post_details.php' (this simply displays a photo of a product & description). Each product has a unique id

Within posts_details.php, I have used to include command to include a form. This form allows users to send me feedback regarding the product.

For some reason the form is not workin. Everytime the submit button is clicked, the alert box warns me that I need to complete the form (even if the form is complete)

The last part of line one doesn't seem to work. It's not picking up the post_id

Can anyone please help ??

post a comment

     <form method="post" action="post_details.php?post= <?php echo $post_id; ?>">  


    <table width "600">

         <tr>
            <td>Your email:</td>
            <td><input type="text" name="comment_email"/></td>
        </tr>

         <tr>
            <td>Your Comment:</td>
            <td><textarea name="comment" cols="35" rows="16"/></textarea></td>
        </tr>

          <tr>
            <td><input type="submit" name="submit" value="postcom"/></td>
        </tr>
    </table>
</form> 


 <?php                               

    if(isset($_POST['comment'] )) {

        $comment_email = $POST['comment_email'];
        $comment = $POST['comment'];

       if( $comment_email=='' OR $comment=='') {   

           echo "<script>alert('Please complete form')</script>";

           echo "<script>window.open('post_details.php?post=post_id')</script>";

           exit(); 

       }

       else {

           echo "complete";   
       }

    }    
?>
1
  • Use === instead of == to check if a string is empty. Commented Aug 30, 2014 at 11:12

1 Answer 1

1

You have error here

if(isset($_POST['comment'] )) {

    $comment_email = $POST['comment_email'];
                      ^
    $comment = $POST['comment']; 
                ^
    ....

Instead of $POST it must be $_POST['comment_email'] and $_POST['comment']

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Vikas ! that's great that worked! although line one seems to be failing, it's not picking up the post_id. Any ideas? <form method="post" action="post_details.php?post= <?php echo $post_id; ?>"
From where you are getting the $post_id ?
empty("0") returns true. Rather use comparison with === '' to check if a $_POST variable is empty.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.