-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?

Phil
  • 157,677
  • 23
  • 242
  • 245
Mark Mitchell
  • 43
  • 1
  • 4
  • I just realized that the ending form is not I fixed it, but still having the same issue – Mark Mitchell Jun 13 '18 at 01: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 '18 at 01:59
  • 2
    You need to run PHP through a server so it’s interpreted; you’re viewing it as HTML. – elixenide Jun 13 '18 at 02: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 '18 at 02: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 '18 at 02:12

1 Answers1

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.