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);
}
?>