TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
View Poll Results: Is this tutorial helpful to you?
Yes, Very helpful! 0 0%
Yes, but not 100% helpful. 0 0%
No, I didn't understand everything. 0 0%
No, I didn't understand anything at all. 0 0%
Voters: 0. You may not vote on this poll

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11-07-2011, 10:38 PM   #1 (permalink)
HersheysBlog.com
 
Hershey's Avatar
 
Join Date: Nov 2011
Posts: 15
Thanks: 0
Hershey is on a distinguished road
Application 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!

Resources:
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.

Appreciation:
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:
  • My Father
  • PHP & MySQL books (I have soo many of them)
  • Tim Kulig - helping a little bit along the way
  • PHP.net

Definitions and Useful Terms
---------------------------

What is PHP?
PHP 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.

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.


Using PHP
---------------------------

IN THIS PART
  1. PHP Crash Course
  2. Storing and Retrieving Data
  3. Using Arrays
  4. String Manipulation and Regular Expressions
  5. Reusing Code and Writing Functions
  6. Object-Oriented PHP

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:
  • Embedding PHP in HTML
  • Adding dynamic content
  • Accessing form variables
  • Identifiers
  • User declared variables
  • Variable types
  • Assigning values to variables
  • Constants
  • Variable scope
  • Operators and precedence
  • Expressions
  • Variable functions
  • Making decisions with if, else, and switch
  • Iteration: while, do and for loops

Using PHP
In 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.

Figure 1.1
Bob's initial order form only records products and quantities.


Listing 1.1 orderform.html—HTML for Bob’s Basic Order Form
Code:
<form action="processorder.php" method=post>
<table border=0>
<tr bgcolor=#cccccc>
<td width=150>Item</td>
<td width=15>Quantity</td>
</tr>
<tr>
<td>Tires</td>
<td align="center"><input type="text" name="tireqty" size="3"
maxlength="3"></td>
</tr>
<tr>
<td>Oil</td>
<td align="center"><input type="text" name="oilqty" size="3" maxlength="3"></td>
</tr>
<tr>
<td>Spark Plugs</td>
<td align="center"><input type="text" name="sparkqty" size="3"
maxlength="3"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Submit Order"></td>
</tr>
</table>
</form>
The first thing to notice is that we have set the form’s action to be the name of the PHP script that will process the customer’s order. (We’ll write this script next.) In general, the value of the ACTION attribute is the URL that will be loaded when the user presses the submit button.The data the user has typed in the form will be sent to this URL via the method specified in the METHOD attribute, either GET (appended to the end of the URL) or POST (sent as a separate packet).

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:

Code:
<html>
<head>
<title>Bob's Auto Parts - Order Results</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Order Results</h2>
</body>
</html>
Notice, how everything we’ve typed so far is just plain HTML. It’s now time to add some simple PHP code to our script.

Embedding PHP in HTML
Under the <h2> heading in your file, add the following lines:
PHP Code:
<?php
echo '<p>Order processed.</p>';
?>
Save the file and load it in your browser by filling out Bob’s form and clicking the Submit Order button. You should see something similar to the output shown in Figure 1.2:

Figure 1.2
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:
Code:
<html>
<head>
<title>Bob's Auto Parts - Order Results</title>
</head>
<body>
<h1>Bob's Auto Parts</h1>
<h2>Order Results</h2>
<p>Order processed.</p></body>
</html>
None of the raw PHP is visible.This is because the PHP interpreter has run through the script and replaced it with the output from the script.This means that from PHP we can produce clean HTML viewable with any browser—in other words, the user’s browser does not need to understand PHP.

This illustrates the concept of server-side scripting in a nutshell.The PHP has been interpreted and executed on the Web server, as distinct from JavaScript and other client-side technologies that are interpreted and executed within a Web browser on a user’s machine.


Next Tutorial!
We will talk about the following:
  • HTML
  • PHP tags
  • PHP statements
  • Whitespace
  • Comments

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!
Send a message via MSN to Hershey Send a message via Skype™ to Hershey
Hershey is offline  
Reply With Quote
Old 11-07-2011, 10:42 PM   #2 (permalink)
HersheysBlog.com
 
Hershey's Avatar
 
Join Date: Nov 2011
Posts: 15
Thanks: 0
Hershey is on a distinguished road
Default

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.
Send a message via MSN to Hershey Send a message via Skype™ to Hershey
Hershey is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
10 PHP Myths Dispelled Wildhoney General 9 06-15-2009 06:55 AM
any good sites to learn php from beginner to super expert php programer?? chikooo Absolute Beginners 5 03-03-2009 09:02 PM
PHP Compressor Kalle Script Giveaway 8 05-28-2008 12:14 AM
PHP Beginner cubeshark Member Introductions 3 09-18-2005 02:16 AM
I'm absolute beginner of PHP Positive Absolute Beginners 10 04-18-2005 07:48 PM


All times are GMT. The time now is 11:48 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design