Build Your Own Database Driven Web Site Using PHP & MySQL Not Working

So, I’m on part 1 of the tutorial. I’ve reached the “Your First PHP Script” section. I’ve made the script in the Komodo IDE, as was recommended, and then when I typed into Safari “http://localhost:8888/today.php” it gives me a 404 Not Found error. I’ve checked into MAMP, and the Apache server is running, and the port is 8888, but it simply doesn’t work. If I use the “Preview Buffer In Browser” option in the Komodo IDE, chose /Applications/Safari.app, then specify “Preview with this file”, the file is shown in Safari, but in code form. Safari simply takes what I’ve written in Komodo, and shows it on the screen. When I do that, the URL for the file is “file:///Users/USR/Desktop/Shenanigans/PHP%20Shenanigans/today.php”. Any fixes?

Did you by any chance forget to put <?php ... ?> around your php code?

@WebMachine No, I don’t think so. Here’s a copy of the code I used.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title>Today's Date</title>
        <meta http-equiv="content-type"
              content="text/html; charset=utf-8"/>
    </head>
    <body>
        <p>Today's date (according to this web server) is
            <?php
                echo date('l, F dS Y.');
            ?>
        </p>
    </body>
</html>

That code works for me. But I use XAMPP so my path is http://localhost/today.php.

I guess someone else will have to try to figure this one out. Sorry.

I notice the book suggests changing the port from 8888 to 80 in MAMP, which would allow you to use the same path as WebMachine. Have you tried that?

@TechnoBear First of all, you mean the Apache port, correct? Second, if I do that it gives me the same error and tells me “Not Found. The requested URL /today.php was not found on this server.”

Yes, sorry, I should have been more specific. So you can set up MAMP OK to have Apache run on port 80, but you still get a 404 error for that file? It sounds as if there’s a problem in the file path.

@TechnoBear Do you think you could help me with that? Should I put the file in /Applications/MAMP/htdocs/?

Aha! Now it works! Thank you for your help! It seems that Kevin forgot to mention that you should put the files in /Applications/MAMP/htdocs/.

1 Like

Glad you managed to work it out for yourself. Hopefully that’s you all set now, but if you have any more questions, you know where to come.

I moved 3 posts to a new topic: SQL error (Build Your Own Database Driven Web Site Using PHP & MySQL)

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.