PHO & MysQl 101
PHO & MysQl 101
PHP Basics
PHP is one of the most popular languages used on the internet. If you are a beginner or are interested in learning, then this is the place for you. By mastering the PHP basics you can open up a whole world of possibilities for your website.
Before You Start
Here are some simple things you need to know before you write your first line of PHP. It is important to have the tools you need ready, to help make learning PHP a less frustrating process.
Learning PHP
Learning PHP can be very rewarding. Once you get started you'll be surprised at how simple it really is. Our tutorials walk you though using simple easy to understand language, so even a non-programer can learn PHP with ease.
PHP is one of the most popular languages used on the internet. If you are a beginner or are interested in learning, then this is the place for you. By mastering the PHP basics you can open up a whole world of possibilities for your website.
- Before You Start
Learning PHP
Before You Start
Here are some simple things you need to know before you write your first line of PHP. It is important to have the tools you need ready, to help make learning PHP a less frustrating process.
- What is PHP?
What is a Plain Text Editor?
What is FTP and how do I use it?
How to CHMOD in FTP
Brush up on HTML basics
Learning PHP
Learning PHP can be very rewarding. Once you get started you'll be surprised at how simple it really is. Our tutorials walk you though using simple easy to understand language, so even a non-programer can learn PHP with ease.
- PHP 101
PHP Loops
PHP Functions
PHP with HTML
PHP Time and Calendars
PHP Forms
PHP Redirection
PHP Countdowns
PHP Math Functions
PHP Variables
Your Server's PHP
What is PHP & MYSQL
PHP is a scripting language that is often imbedded into HTML to add functions HTML alone can't do. PHP allows you to collect, process and utilize data to create a desired output. In short, it let's you interact with your pages.
PHP is able to preform a number of tasks including printing data, making numeric calculations (such as addition or multiplication), making comparisons (which is bigger, are they equal, etc) and making simple boolean choices. From this you can create more complex loops and functions to make your page generate more specialized data.
MySQL is a relational database system that is used to store information. MySQL can store many types of data from something as tiny as a single character to as large as complete files or graphics. Although it can be accessed by most programing languages, it is often coupled with PHP because they work together with ease.
Information stored in a MySQL database hosted on a web server can be accessed from anywhere in the world with a computer. This makes it a good way to store information that needs the ability to change over time, but also needs to be accessed over the net. Some examples that can utilize MySQL are a web message board or a customer's shipping status.
Index: What are PHP and MySQL
How do PHP & MYSQL Work Together
PHP and MySQL compliment each other to do with neither can do alone. PHP can collect data, and MySQL can in turn store the information. PHP can create dynamic calculations, and MySQL can provide it with the variables it uses. PHP can create a shopping cart for your web store, but MySQL can then keep the data in a format PHP can use to create receipts on demand, show current order status, or even suggest other related products.
Although PHP and MySQL can each be used independently, when you put them together it opens up countless possibilities for your site. As the internet progresses, it becomes more and more necessary to deliver dynamic content to keep up with the demands of web surfers and their desire to have information instantly delivered to them online. By learning to use PHP and MySQL you can deliver this information to them on demand.
Running PHP & MYSQL
In order to do some of our tutorials (or program with PHP and MySQL in general) you need to be able to run PHP and MySQL. Although most free hosts do not have PHP and MySQL support there are some that do, and there are also many low cost hosting options available. If you already have hosting and are unsure if you have PHP and MySQL support you should contact your host directly. If you are shopping for hosting be sure that they support PHP and that your package includes at least one MySQL database.
Another option is to install PHP and MySQL directly onto your Windows computer. If you are a Mac user you already have the capability and just need to activate PHP and MySQL.
PHP is able to preform a number of tasks including printing data, making numeric calculations (such as addition or multiplication), making comparisons (which is bigger, are they equal, etc) and making simple boolean choices. From this you can create more complex loops and functions to make your page generate more specialized data.
MySQL is a relational database system that is used to store information. MySQL can store many types of data from something as tiny as a single character to as large as complete files or graphics. Although it can be accessed by most programing languages, it is often coupled with PHP because they work together with ease.
Information stored in a MySQL database hosted on a web server can be accessed from anywhere in the world with a computer. This makes it a good way to store information that needs the ability to change over time, but also needs to be accessed over the net. Some examples that can utilize MySQL are a web message board or a customer's shipping status.
Index: What are PHP and MySQL
How do PHP & MYSQL Work Together
PHP and MySQL compliment each other to do with neither can do alone. PHP can collect data, and MySQL can in turn store the information. PHP can create dynamic calculations, and MySQL can provide it with the variables it uses. PHP can create a shopping cart for your web store, but MySQL can then keep the data in a format PHP can use to create receipts on demand, show current order status, or even suggest other related products.
Although PHP and MySQL can each be used independently, when you put them together it opens up countless possibilities for your site. As the internet progresses, it becomes more and more necessary to deliver dynamic content to keep up with the demands of web surfers and their desire to have information instantly delivered to them online. By learning to use PHP and MySQL you can deliver this information to them on demand.
Running PHP & MYSQL
In order to do some of our tutorials (or program with PHP and MySQL in general) you need to be able to run PHP and MySQL. Although most free hosts do not have PHP and MySQL support there are some that do, and there are also many low cost hosting options available. If you already have hosting and are unsure if you have PHP and MySQL support you should contact your host directly. If you are shopping for hosting be sure that they support PHP and that your package includes at least one MySQL database.
Another option is to install PHP and MySQL directly onto your Windows computer. If you are a Mac user you already have the capability and just need to activate PHP and MySQL.
Basic PHP Syntax
PHP is a server side scripting language used on the Internet to create dynamic web pages. It is often coupled with MySQL, a relational database server that can store the information and variables the PHP files may use. Together they can create everything from the simplest web site to a full blown business web site, an interactive web forum, or even an online role playing game.
Before we can do the big fancy stuff we must first learn the basics from which we build on.
1. Start by creating a blank file using any program that can save in plain text format.
2. Save your file as a .PHP file, for example mypage.php. Saving a page with the .php extension tells your server that it will need to execute the PHP code.
3. Enter the statement <?php to let the server know that there is PHP code coming up.
4. After this we would enter the body of our PHP program.
5. Enter the statement ?> to let the browser know the PHP code is done.
Every section of PHP code starts and ends by turning on and off PHP tags to let the server know that it needs to execute the PHP in between them. Here is an example:
<?php //on
//and
//off ?>
Everything between the “?”s is read as PHP code. The <?php statement can also be phrased as simply <? if desired. Anything outside of these PHP tags is read as HTML, so you can easily switch between PHP and HTML as needed. This will come in handy later in our lessons.
Comment
If you want something to be ignored (a comment for example) you can put // before it as I did in our example on the previous page. There are a few other ways of creating comments within PHP, which I will demonstrate below:
<?php
//A comment on a single line
#Another single line comment
/*
Using this method
you can create a larger block of text
and it will all be commented out
*/
?>
One reason you may want to put a comment in your code is to make a note to yourself about what the code is doing for reference when you edit it later. You may also want to put comments in your code if you plan on sharing it with others and want them to understand what it does, or to include your name and terms of use within the script.
PRINT and ECHO Statement
First we are going to learn about the echo statement, the most basic statement in PHP. What this does is output whatever you tell it to echo. For example:
<?php echo "I like Asohk" ?>
This would return the statement I like About. Notice when we echo a statement, it is contained within quotation marks [“”].
Another way to do this is to use the print function. An example of that would be:
<?php print "I like Asohk" ?>
There is a lot of debate about which is better to use or if there is any difference at all. Apparently in very large programs that are simply outputting text the ECHO statement will run slightly faster, but for the purposes of a beginner they are interchangeable.
Another thing to keep in mind is that all of your print/echoing is contained between quotation marks. If you want to use a quotation mark inside of the code, you must use a backslash:
<?php print "Billy said \"I like Asohk too\"" ?>
When you are using more than one line of code inside your php tags, you must separate each line with a semicolon [;]. Below is an example of printing multiple lines of PHP, right inside your HTML:
<html>
<head>
<title>PHP Test Page</title>
</head>
<body>
<center><b>
<?php
print "I like Asohk";
print "<br>";
print "Billy said \"I like Asohktoo\""
?>
</b></center>
</body>
</html>
As you can see, you can insert HTML right into your php print line. You can format the HTML in the rest of the document as you please, but remember to save it as a .php file.
Before we can do the big fancy stuff we must first learn the basics from which we build on.
1. Start by creating a blank file using any program that can save in plain text format.
2. Save your file as a .PHP file, for example mypage.php. Saving a page with the .php extension tells your server that it will need to execute the PHP code.
3. Enter the statement <?php to let the server know that there is PHP code coming up.
4. After this we would enter the body of our PHP program.
5. Enter the statement ?> to let the browser know the PHP code is done.
Every section of PHP code starts and ends by turning on and off PHP tags to let the server know that it needs to execute the PHP in between them. Here is an example:
<?php //on
//and
//off ?>
Everything between the “?”s is read as PHP code. The <?php statement can also be phrased as simply <? if desired. Anything outside of these PHP tags is read as HTML, so you can easily switch between PHP and HTML as needed. This will come in handy later in our lessons.
Comment
If you want something to be ignored (a comment for example) you can put // before it as I did in our example on the previous page. There are a few other ways of creating comments within PHP, which I will demonstrate below:
<?php
//A comment on a single line
#Another single line comment
/*
Using this method
you can create a larger block of text
and it will all be commented out
*/
?>
One reason you may want to put a comment in your code is to make a note to yourself about what the code is doing for reference when you edit it later. You may also want to put comments in your code if you plan on sharing it with others and want them to understand what it does, or to include your name and terms of use within the script.
PRINT and ECHO Statement
First we are going to learn about the echo statement, the most basic statement in PHP. What this does is output whatever you tell it to echo. For example:
<?php echo "I like Asohk" ?>
This would return the statement I like About. Notice when we echo a statement, it is contained within quotation marks [“”].
Another way to do this is to use the print function. An example of that would be:
<?php print "I like Asohk" ?>
There is a lot of debate about which is better to use or if there is any difference at all. Apparently in very large programs that are simply outputting text the ECHO statement will run slightly faster, but for the purposes of a beginner they are interchangeable.
Another thing to keep in mind is that all of your print/echoing is contained between quotation marks. If you want to use a quotation mark inside of the code, you must use a backslash:
<?php print "Billy said \"I like Asohk too\"" ?>
When you are using more than one line of code inside your php tags, you must separate each line with a semicolon [;]. Below is an example of printing multiple lines of PHP, right inside your HTML:
<html>
<head>
<title>PHP Test Page</title>
</head>
<body>
<center><b>
<?php
print "I like Asohk";
print "<br>";
print "Billy said \"I like Asohktoo\""
?>
</b></center>
</body>
</html>
As you can see, you can insert HTML right into your php print line. You can format the HTML in the rest of the document as you please, but remember to save it as a .php file.
Permissions in this forum:
You cannot reply to topics in this forum
|
|