Building a cool website using HTML, PHP and MySQL

Getting Started

Most web tutorials gently ease you into the topic with simple programs that show you how to have the computer write "Hello World!" on the screen. An example:

hellow world script

In order to work this tutorial, you will need access to a web host. Your own computer can be a webhost. If you have a mac, the necessary software is installed when you purchase your machine, but disabled. The reason for that is when your computer is hooked up to the internet, access works both ways. Other folks can find your computer and, if it is not well protected, use it for their own purposes. Setting up your own machine as a web host is very easy, but risky. If you are using a tutorial such as this one, you are far better off using a hosting service. Most of which charge nominal fees and offer help with various technical issues that never seem to come up in a tutorial.

Hosting plans also take care of the SQL installation, which is not offered on either the Mac or the PC. Installing MySQL is relatively easy. If you are starting out at this level, you might want to wait before installing it on your own machine.

if you are going to use a hosting service, you will also want an FTP client There are many choices such as:

You may also want a text editor.

Each web host has slightly different ways of accessing your file space. I can't do a comprehensive tutorial on this, as anything I say here will be wrong most of the time. However there are enough similarities that working from what I have here you can guess your way through the particulars of each system.

When you sign on to the web host, you will be a the root of your account. This is where most of the utilites of your account live. Your scripts don't go here For my web host, your scripts go in the "public_html" directory.

A basic PHP script is illustrated above. It starts out with the commnand to the host interpeter to render the page as a php script: <?php What follows is a basic PHP command, followed by the instruction to stop parsing as PHP.

One of the reasons that PHP is so popular is that it can be interpolated into the web page as needed. You an build regular HTML and Javascript on the page and build the php script as needed. A php script page will have several places where it is exclusivly HTML code, and several places where it will be exclusive PHP, and even a few places where both are mixed

A PHP page can look like a regular html page except for the php elements. If you have hosting and text editor, try the following text:

<HTML>
<HEAD>
<TITLE>Sample PHP Page</TITLE>
</HEAD>
<BODY>
Hello World, this is a standard web page.
anything we type goes right on the screen
pretty much the way we type it.
with no interpretation.
However, PHP interprets instructions.
<?PHP 
for ($beer=99;  $beer>0; $beer--)   //a loop. 
// define a variable, 
//repeat it until the variable hits a value,
// change the variable
{$burp=$beer-1;
echo "$beer bottles of beer on the wall,"; 
echo "$beer bottles of beer!";
echo "Take one down, pass it around";
if ($burp>0 )//a condition, then do a statement
{
echo ", $burp bottles of beer on the wall";
echo " <br  /> \n";
}
else // if the condition is false, do something else
{echo ". \n  all gone!  \n";}
}
echo "belch!\n";//after the loop is done, then continue
?>
</body>
</html>

You can type it in directly or copy paste into your text editor. When you save it to your web host, save it as somefile.php You can see how it is supposed to look like here


In addition to its integration with HTML, PHP also integrates very well with MySQL. The combination of the three technologies is what makes for most web pages. All three technologies are simple, but you can build very complex pages from them.

Very much, each complex web page works from the data you wish to present to the user. PHP can be used to access the database, and present the result as the HTML code that presents the information the user wants in its most useful form for the user.

When doing any project it is best to build from a solid foundation. If you have nothing much in the way of a goal, and limited resources, you can throw together some cardboard, tar paper, some loose boards and have a structure that keeps you out of the rain. Building something like Versailles orShoenbrunn takes a bit more thought and planning. Of course, lots of websites look a bit like the Winchester House. But that is not where we want to go.

So the plan for the beginning here is to talk about databases and normalization first, then get into the world of MySQL, but stopping along the way to discuss basic security as we go along. After we build the foundation, then we can work on the rest of the structure, making sure all the while that the plumbing and wiring are up to code, so that the content you put into the page is secure and the user has a good experience.

Since this page is mostly about set up, one final word here about MySQL set up. Each host does it just a little differently. Sometimes the set up is very simple, and sometimes it can be complex. The host I use is on the complex side. Before you can use MySQL you have to set up accounts and databases,and associate the account with the database, and set permissions. This is best practice. You want your accounts to have minimal permission for specific functions.

One big advantage to Hosts is they use PHPMyAdmin, which you can use instead of working with the terminal for your MySQL work.

Resources

CSS, the Missing Manual David Sawyer McFarland
PHP and MySQL Larry Ulman
Manga Guide to Databases Shoko Azuma

useful programming resources

W3 Schools programming resources

Tiztag programming resources

About.com

Web site security rules

An HTML validation tool, Very Important

Lists and CSS styles elegantly explained

Step by step lessons in PHP programming

Web Developer Notes

SQL Zoo


Useful tools

Text Wrangler - General Purpose text editor

Transmit Text Edit and FTP client

The Total Validator validation tool


Other stuff I write

A Dark and Stormy Knight

Change

| page 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

Last edit December 16, 2010