How To..
Or if your one of those smart guys, you can check the all-in-one page that has all the above functions dumped into one little page.
Before you Start!
These pages are to show you HOW PHP works, it is not a walkthrough! This is how I personally learned PHP, I looked at someone elses code and took my bits from it to make my own, the following pages are pieces of code you can use to copy your bits from.
The following pages rely on a MySQL database, to run any of the scripts you see here for yourself you'll need;
a database named 'learn', once you've created this database run the following query on it:
CREATE TABLE `data_table` (
`id` smallint(6) NOT NULL auto_increment,
`data` text collate latin1_general_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 ;
INSERT INTO `data_table` (`id`, `data`) VALUES
(1, 'This data was already here2..'),
(2, 'And so was this..');
Complete Reference
PHP
- echo - this prints out data following the echo command to the browser.
- $_POST - The post tag holds all the form fields and their data that have been submitted by a form that uses the POST method.
- $_GET - this tag holds an array of the data that has been set in the URI (URL), data is set after the URI file name, after the questionmark, first is the name of the variable, follwed by "=" and the data.
- Double and Single quotes - To echo or define raw data (like html or just text) you have to put the data between brackets so that PHP knows where the data starts and where it ends.
- Single Quotes - Data between single quotes is printed out EXACTLY the way it's inside those quotes.
eg. in this case $test = 'jack', the following: echo 'hello $test'; becomes hello $test
- Double Quotes - Data between double quotes can contain variables, these variables will be evaluated.
eg. in this case $test = 'jack', the following: echo "hello $test"; becomes hello jack
- while - while creates a loop that repeatedly runs the data inside the special brackets untill the execution code (following the normal brackets right after "while" is complete.
- array - an array is a variable that holds multiple fields, which can be referred to by each name of that field, basically an array is a variable that holds other variables.
- variable - a variable is a single piece of connecting characters prefixed by a dollar symbol, this variable can contain data, for example $hello can contain "Hello World!" and when printed out to the browser it will print out "Hello World!" rather than $hello.
MySQL
uppercase characters are MySQL commands, lowercase characters are custom data.
- INSERT INTO - tells MySQL that it is going to INSERT data into the database, following to INSERT INTO is the table name you are inserting data into.
- Brackets "(xxx)" - Brackets contain multiple data, as you are not just adding one field. In the example the first set of data inside brackets are the fields you are inserting data into
- VALUES - tells MySQL it is going to insert the values into the defined table and fields, the following set of data inside the brackets is the data you are inserting.
- WHERE - This specifies what rows you want to receive from the table, in the example we're getting a specific identification number from the id row.
So we're getting data from the table WHERE the id is a specific number.
- SELECT - tells MySQL that it is going to SELECT data from the database.
- Brackets "(xxx)" - Brackets contain multiple data, as you are not just adding one field. In the example the first set of data inside brackets are the fields you are inserting data into
- DELETE FROM - tells MySQL to delete data from the database, following FROM is the table name, note that if you don't specify a decent WHERE all data in the table will be deleted..