-1

I have PHP code inside an HTML file but the file extension is .php, when I run it it comes out as a plain text.

Keep in mind I don't want it to go to a server online or anything. I am writing comments and saving them locally. Here is my code below:

    <html>
<form method="post" action="">
<label> Name: 
<input type="text" name="name"><br>
</label>
<br>
<label> Comments: 
<br>
<textarea cols="45" rows="5" name="Comments"></textarea></label><br>
<br>
<input type="submit" name="post" value="post"> 



</html>

<?php


$name = $_POST ["name"];
$text = $_POST ["comments"];
$post = $_POST ["Post"];

if ($post){

#write#
$write= fopen("com.text", "a+");
fwrite($write, "<u><b> $name</b></u><br>$text<br>");
fclose($write);

#Display#
$read= fopen("com.txt", "r+t");
echo "All Comments:<br> ";

while(!feof($read)){
echo fread($read, 1024);
}

fclose($read);
}

else {

#Display#
$read= fopen("com.txt", "r+t");
echo "All Comments: <br> ";

while(!feof($read)){
echo fread($read, 1024);
}

fclose($read);
}

?>
S.L. Barth
  • 8,058
  • 71
  • 49
  • 63
rowid
  • 7
  • 1
  • 2
    Your URL is something like file:// ? If yes, setup a local server like wamp/mamp/lamp/xamp, easyPhp or other – Xenofexs Dec 15 '16 at 10:02

1 Answers1

0

You need to have a webserver software installed, that is capable of interpreting php and delivering it to you.

Have a look at MAMP or XAMPP for the start.

janrop
  • 191
  • 2
  • 9