I am trying to do a simple comment function, where you write your name and comment in different fields, press submit and than the comment appears. In my PHP file, I have this : <?php $name = $_POST['name']; $comment = $_POST['comment']; <div> <div>Name is <?php echo $name ?></div> <div>Comment is <?php echo $comment ?></div> </div> When I upload it and press the submit button, it says: Parse error: syntax error, unexpected '<' in (filename) on line # I am assuming that the error has to do with either the division that is starting or the second <?php that starts.... What am I supposed to change? Thank you.
You need to close your PHP code with ?> before you start outputting HTML directly. Also, you should never, ever output user input to the page without first sanitising it. I could POST whatever I want and have it outputted on to the page with your above code. Something like this: <?php $name = htmlentities($_POST['name']); $comment = htmlentities($_POST['comment']); ?> <div> <div>Name is <?php echo $name ?></div> <div>Comment is <?php echo $comment ?></div> </div> PHP:
Use this : <?php $name = $_POST['name']; $comment = $_POST['comment']; ?> <div> <div>Name is <?php echo $name ?></div> <div>Comment is <?php echo $comment ?></div> </div> Code (markup):