I am extremely knew to working with databases and servers and just downloaded MAMP. I have a website I made in html and css and want to inject a php script to it. I have saved the file in .php and when I navigate to it from the localhost port on my browser, none of the html is displayed. It only shows a blank white page. There is probably a really obvious answer but I’ve been searching google for an hour and haven’t found a solution.
This is the php script. It is wrapped in a
tag everything else in the document is html.
<?PHP
$filelocation = "Text.txt";
if (!file_exists($filelocation)) {
echo "Couldn't find datafile, please contact the administrator.";
}
else {
$newfile = fopen($filelocation,"r");
$content = fread($newfile, filesize($filelocation));
fclose($newfile);
}
$content = stripslashes($content):
$content = htmlentities($content):
$content = nl2br($content);
echo $content;
?>
Most likely there’s an error in your PHP code and it can’t be parsed. Check the server logs to see what the error message is.
That seems to be valid PHP at a glance.
You could read the file more easily by doing…
but that’s incidental.
Turn on Error reporting in your php.ini file and then restart your webserver. This should give more detailed error information. You should also check your server error logs as there’s usually something in there too.
Are you getting an HTTP 500 response code with the blank page? Also, are you sure the file in question actually has any contents?