PHP Beginner Guide #1
Hello, this tutorial will be a very high quality tutorial, getting in-depth with everything related to PHP & MySQL. Please take the time to look at the resources and appreciations. Let me know how you liked this tutorial. Please let me know of any spelling/grammar/typos/or any other types of errors you may find. Thanks!
Here are a few of the many different resources that can help you advance in the language of PHP:
PHP.net :: An awesome sites to view sources and get some help.
W3Schools :: Worlds largest web development site!
MySQL :: The world's most popular open source database.
phpMyAdmin :: Handles the administration of one or more MySQL servers over the web. Written in PHP.
I would like to thank all the sites above in the resources, of course HF's PHP forum, which has helped me along the way! I would also like to thank the following:
Definitions and Useful TermsPHP is a server-side scripting language designed specifically for the Web. Within an HTML page, you can embed PHP code that will be executed each time the page is visited/loaded. Your PHP code is interpreted at the Web server and generates HTML or other output that the visitor will see.
What is PHP?
PHP was conceived in 1994 and was originally the work of one man, Rasmus Lerdorf. It was adopted by other talented people and has gone through three major rewrites to bring us the broad, mature product we see today. As of January 2001, it was in use on nearly five million domains worldwide, and this number is growing rapidly. You can see the current number @ http://www.php.net/usage.php (Thanks to chad12146 I found this useful link!)
PHP is an Open Source product. You have access to the source code. You can use it, alter it, and redistribute it all without charge or any kind of expense.
PHP originally stood for Personal Home Page but was changed in line with the GNU recursive naming convention (GNU - Gnu's Not UNIX) and now stands for PHP Hypertext Preprocessor.
The current major version of PHP is 5. This version has seen some major improvements to the language.
What is MySQL?MySQL (pronounced My-Ess-Que-Ell) is very fast, robust, relational database management system (RDBMS). A database enables you to efficiently store, search, and retrieve data. The MySQL server controls access to your data to ensure that only authorized users can obtain access. Hence, MySQL is a multi-user, multi-threaded server. It uses SQL (Structured Query Language), the standard database query language worldwide. MySQL has been publicly available since 1996, but has a development history going back to 1979.
Why Use PHP and MySQL?When setting out to build an e-commerce site, there are many different products that you could use. You will need to choose hardware for the Web server, and operating system, Web server software, a database management system, and a programming or scripting language.
Some of these choices will be dependent on the others. For example, not all operating systems will run on all hardware not all scripting languages can connect to all databases, and so on.
One of the nice features of PHP is that it is available for Windows, many versions of UNIX, and with any fully-functional Web Server. MySQL is similarly versatile.
IN THIS PART
PHP Crash Course
This part gives you a quick overview of PHP syntax and language constructs. If you are already a PHP programmer, it might full some gaps in your knowledge.if you have a background using C, ASP, or another programming language, it will help you get up to speed quickly.
In this tutorial you'll learn how to use PHP by working through lots of real world examples, taken from the experience in building e-commerce sites. Often programming tutorials teach basic syntax with very simple examples. I have chosen not to do that. I recognize that often what you want to do is get something up and running, to understand how the language is used, rather than ploughing through yet another syntax and function reference that's no better than the online manual.
Try the examples out--type them in or copy them from this tutorial, change them, break them, and learn how to fix them again. The more practice, the better!
In this part, we'll begin with the example of an online product order form to learn how variables, operators, and expressions, are used in PHP. We will also cover variable types and operator precedence. You will learn how to access from variables and how to manipulate them by working out the total and tax customer order.
You will then develop the online order form example by using a PHP script to validate the input data. We'll examine the concept of Boolean values and give examples of using "if, else, the ?: operator, and the switch statement."
Finally, we'll explore looping by writing some PHP to generate repetitive HTML tables.
Key topics you will learn in the tutorial include:
Using PHPIn order to work through the examples in the tutorial, you will need access to a Web server with PHP installed, or install it on your personal computer. To get the most from the examples and case studies, you should run them and try changing them. To do this, you'll need a testbed where you can experiment.
If PHP is not installed on your machine, you will need to begin by installing it, or getting your system administrator to install it for you. IF you ever need any help with anything related to PHP/MySQL/HTML/CSS/or anything web related, just ask me. I will be glad to help!
Sample Application: Bob's Auto Parts
One of the most common applications of any server side scripting language is processing HTML forms. You'll start learning PHP by implementing an order form for Bob's Auto Parts, a fictional spare parts company. All the code will be given in the "code" brackets, so please test them out. If you need help, ask.
The Order Form
Right now, Bob's HTML programmer has gotten as far as setting up an order form for the parts that Bob sells. The order form is shown in Figure 1.1. This is a relatively simple order form, similar to many you have probably seen while surfing.The first thing Bob would like to be able to do is know what his customer ordered, work out the total of the customer’s order, and how much sales tax is payable on the order. Part of the HTML for this is shown in Listing 1.1.There are two important things to notice in this code.
Bob's initial order form only records products and quantities.
Listing 1.1 orderform.html—HTML for Bob’s Basic Order Form
The second thing you should notice is the names of the form fields tireqty, oilqty, and sparkqty.We’ll use these names again in our PHP script. Because of this, it’s important to give your form fields meaningful names that you can easily remember when you begin writing the PHP script. Some HTML editors will generate field names like field23 by default.These are difficult to remember.Your life as a PHP programmer will be easier if these names reflect the data that is typed into the field.
You might want to consider adopting a coding standard for field names so that all field names throughout your site use the same format.This makes it easier to remember whether, for example, you abbreviated a word in a field name, or put in underscores as spaces.
Processing the Form
To process the form, we’ll need to create the script mentioned in the ACTION attribute of the FORM tag called processorder.php. Open your text editor and create this file. Type in the following code:
Embedding PHP in HTML
Under the <h2> heading in your file, add the following lines:
Text passed to PHP’s echo construct is echoed to the browser.
Notice how the PHP code we wrote was embedded inside a normal-looking HTML file. Try viewing the source from your browser.You should see this code:
Next Tutorial!We will talk about the following:
Keep updated for the next tutorial!
If you have any questions feel free to ask! I will help you every step of the way! Lets keep the questions on Beginner Level so when people look through this topic/thread, they will find beginner questions that will help them exceed. If you need advance questions answered, just send me a personal/private message! Thank you for understanding!
I understand that this wasn't very helpful with PHP, but this is the start on all of my PHP tutorials. I will frequently create new tutorials from a PHP book I have. Thanks for understanding.
|All times are GMT. The time now is 03:17 AM.|
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0