2

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;
                        ?> 
1
  • post the code you have written so we can see what you are doing. Commented Oct 19, 2012 at 16:25

3 Answers 3

3

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

$content = file_get_contents($filelocation);

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?

Sign up to request clarification or add additional context in comments.

2 Comments

I checked the php error log and there seems to be an error in my line of code which is the bracket that ends the else statement. I can probably figure it out from here, thanks for the help!
You're welcome but I think the problem is the one identified by @LucaBorrione - namely that you've got some : instead of ;. Either way, welcome to SO. Hopefully we'll see you around again
1

You have two syntax errors in your code:

 $content = stripslashes($content):
 $content = htmlentities($content):

They must end with semicolon

 $content = stripslashes($content);
 $content = htmlentities($content);

Besides that, your errors are likely catched and written to logs as said by others.

Comments

0

Most probably you have a php / php syntax error.

On the first line of your .php file write the following:

<?php error_reporting(E_ALL); ?>

this should make the interpreter to show you the errors you have.

Also, more details about your problem won't hurt.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.