-1

I have been trying to follow the code written on youtube for creating a comment section for my website.

I use the following code for the form:

<?php

echo "<form>
<input type=-'hidden' name='uid' value='Anonymous'>
<input type='hidden' name='date' value='".date('Y-m-d H:i:s')."'>
<textarea name='message'></textarea><br>
<button type='submit' name='submit'>Comment</button>
<form>";
?>

However, when I preview in browser it shows the Comment button followed by ""; ?>"

Image of what it shows in the preview - Everything is within the proper fields - I cannot figure out for the life of me what I am doing wrong - I followed the video to the T, and there are tons of comments saying that the code works - https://www.youtube.com/watch?v=1LmPeHX7RRo

Any ideas?

5
  • I just realized that the ending form is not </form> I fixed it, but still having the same issue Jun 13, 2018 at 1:50
  • Remove the closing tag, it will simple cause you no end of drama as you'll see from @LukasBach 's link
    – Darren
    Jun 13, 2018 at 1:59
  • 2
    You need to run PHP through a server so it’s interpreted; you’re viewing it as HTML.
    – elixenide
    Jun 13, 2018 at 2:01
  • It is strongly recommended to avoid the closing ?> in PHP only files, however this should not cause a problem. There might be a problem with your server configuration. Can you find something useful in your logs?
    – sidyll
    Jun 13, 2018 at 2:04
  • 2
    You're opening the file locally in your browser, i.e. without a web server running PHP, so the PHP isn't being parsed and interpreted.
    – j08691
    Jun 13, 2018 at 2:12

1 Answer 1

0

As the @Ed Cottrell's comment says, you can't just run PHP without a server, try installing WampServer

Also, there are 2 problems with the HTML: type=-"hidden" in the first input should be type="hidden", and the closing form that you fixed already.

2
  • Thanks everyone! I've never asked for help before - I really appreciate it! Jun 13, 2018 at 2:13
  • you're welcome, go ahead, install wampserver and you will be ready to go :-) Jun 13, 2018 at 2:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.