<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4358669149008391889</id><updated>2024-08-30T18:46:12.592-07:00</updated><title type='text'>Web Design Tips &amp;amp; Tricks</title><subtitle type='html'>Easy to Learn PHP</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://webdesigntipstrick.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4358669149008391889/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://webdesigntipstrick.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Admin</name><uri>http://www.blogger.com/profile/05350530015134205170</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>9</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4358669149008391889.post-1574770056992789003</id><published>2012-07-12T00:04:00.003-07:00</published><updated>2012-07-12T00:04:37.266-07:00</updated><title type='text'>PHP POST &amp; GET with Example Tutorial</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;b&gt;PHP - POST &amp;amp; GET&lt;/b&gt;&lt;br /&gt;
Recall from the PHP Forms Lesson where we used an HTML form and sent it to a PHP web page for processing. In that lesson we opted to use the the post method for submitting, but we could have also chosen the get method. This lesson will review both transferring methods.&lt;br /&gt;
&lt;b&gt;POST - Review&lt;/b&gt;&lt;br /&gt;
In our PHP Forms Lesson we used the post method. This is what the pertinent line of HTML code looked like:&lt;br /&gt;
&lt;b&gt;HTML Code Excerpt:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;form action=&quot;process.php&quot; method=&quot;post&quot;&gt;
&lt;br /&gt;
&lt;select name=&quot;item&quot;&gt;...&lt;/select&gt;&lt;input name=&quot;quantity&quot; type=&quot;text&quot; /&gt;&lt;br /&gt;
This HTML code specifies that the form data will be submitted to the &quot;process.php&quot; web page using the POST method. The way that PHP does this is to store all the &quot;posted&quot; values into an associative array called &quot;$_POST&quot;. Be sure to take notice the names of the form data names, as they represent the keys in the &quot;$_POST&quot; associative array.&lt;br /&gt;
Now that you know about associative arrays, the PHP code from &quot;process.php&quot; should make a litte more sense.&lt;br /&gt;
&lt;b&gt;PHP Code Excerpt:&lt;/b&gt;&lt;br /&gt;
$quantity = $_POST[&#39;quantity&#39;];&lt;br /&gt;
$item = $_POST[&#39;item&#39;];&lt;br /&gt;
The form names are used as the keys in the associative array, so be sure that you never have two input items in your HTML form that have the same name. If you do, then you might see some problems arise.&lt;br /&gt;
&lt;b&gt;PHP - GET&lt;/b&gt;&lt;br /&gt;
As we mentioned before, the alternative to the post method is get. If we were to change our HTML form to the get method, it would look like this:&lt;br /&gt;
HTML Code Excerpt:&lt;br /&gt;
&lt;br /&gt;
&lt;select name=&quot;item&quot;&gt;...&lt;/select&gt;&lt;input name=&quot;quantity&quot; type=&quot;text&quot; /&gt;&lt;br /&gt;
The get method is different in that it passes the variables along to the &quot;process.php&quot; web page by appending them onto the end of the URL. The URL, after clicking submit, would have this added on to the end of it:&lt;br /&gt;
&quot;?item=##&amp;amp;quantity=##&quot;&lt;br /&gt;
The question mark &quot;?&quot; tells the browser that the following items are variables. Now that we changed the method of sending information on &quot;order.html&quot;, we must change the &quot;process.php&quot; code to use the &quot;$_GET&quot; associative array.&lt;br /&gt;
&lt;b&gt;PHP Code Excerpt:&lt;/b&gt;&lt;br /&gt;
$quantity = $_GET[&#39;quantity&#39;];&lt;br /&gt;
$item = $_GET[&#39;item&#39;];&lt;br /&gt;
After changing the array name the script will function properly. Using the get method displays the variable information to your visitor, so be sure you are not sending password information or other sensitive items with the get method. You would not want your visitors seeing something they are not supposed to!&lt;br /&gt;
Security Precautions&lt;br /&gt;
Whenever you are taking user input and using you need to be sure that the input is safe. If you are going to insert the data into a MySQL database, then you should be sure you have thought about preventing MySQL Injection. If you are going to make a user&#39;s input available to the public, then you should think about PHP htmlentities.&lt;br /&gt;
&lt;b&gt;PHP htmlentities Function&lt;/b&gt;&lt;br /&gt;
Whenever you allow your users to submit text to your website, you need to be careful that you don&#39;t leave any security holes open for malicious users to exploit. If you are ever going to allow user submitted text to be visible by the public you should consider using the htmlentities function to prevent them from running html code and scripts that may be harmful to your visitors.&lt;br /&gt;
&lt;b&gt;PHP - Converting HTML into Entities&lt;/b&gt;&lt;br /&gt;
The htmlentities function takes a string and returns the same string with HTML converted into HTML entities. For example, the string &quot;&lt;script&gt;
&quot; would be converted to &quot;&amp;lt;script&amp;gt;&quot;.&lt;/p&gt;
&lt;p&gt;
By converting the &lt; and &gt; into entities, it prevents the browser from using it as an HTML element and it prevents the code from running if you were to display some user&#39;s input on your website.&lt;/p&gt;
&lt;p&gt;
This may seem a little complicated, but if you think of the way a browser works, in separate stages, it becomes a little easier. Let&#39;s look at the way the function htmlentities changes the data at three different levels: in PHP, in raw HTML and in the web browser. The sample string is a bad script that will redirect visitors to the malicious user&#39;s own website.&lt;/p&gt;
&lt;p&gt;
&lt;b&gt;PHP Code:&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;
// An imaginary article submission from a bad user&lt;/p&gt;
&lt;p&gt;
// it will redirect anyone to example.com if the code is run in a browser&lt;/p&gt;
&lt;p&gt;
$userInput = &quot;I am going to hax0r your site, hahaha!&lt;/p&gt;
&lt;p&gt;
&lt;script type=&#39;text/javascript&#39;&gt;&lt;/p&gt;
&lt;p&gt;
window.location = &#39;http://www.example.com/&#39;&lt;/p&gt;
&lt;p&gt;

&lt;/script&gt;&#39;&quot;;&lt;br /&gt;
//Lets make it safer before we use it&lt;br /&gt;
$userInputEntities = htmlentities($userInput);&lt;br /&gt;
//Now we can display it&lt;br /&gt;
echo $userInputEntities;&lt;br /&gt;
The HTML output of the above script would be as follows:&lt;br /&gt;
Safe Raw HTML Code:&lt;br /&gt;
I am going to hax0r your site, hahaha!&lt;br /&gt;
&amp;lt;script type=&#39;text/javascript&#39;&amp;gt;&lt;br /&gt;
window.location = &#39;http://www.example.com/&#39;&lt;br /&gt;
&amp;lt;/script&amp;gt;&#39;&lt;br /&gt;
If we had not used htmlentities to convert any HTML code into safe entities, this is what the raw HTML code would be and it would have redirect a visitor to example.com.&lt;br /&gt;
Dangerous Raw HTML Code:&lt;br /&gt;
I am going to hax0r your site, hahaha!&lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
&lt;/p&gt;
&lt;p&gt;
window.location = &#39;http://www.example.com/&#39;&lt;/p&gt;
&lt;p&gt;

&lt;/script&gt;&#39;&lt;br /&gt;
Those two HTML code examples are what you would see if you were to view source on the web page. However, if you were just viewing the output normally in your browser you would see the following.&lt;br /&gt;
Safe Display:&lt;br /&gt;
I am going to hax0r your site, hahaha! &lt;script type=&quot;text/javascript&quot;&gt;
 window.location = &#39;http://www.example.com/&#39; 
&lt;/script&gt;&#39;&lt;br /&gt;
&lt;b&gt;Dangerous Display:&lt;/b&gt;&lt;br /&gt;
You&#39;d see whatever spammer site that the malicious user had sent you to. Probably some herbal supplement site or weight loss pills would be displayed.&lt;br /&gt;
When Would You Use htmlentities?&lt;br /&gt;
Anytime you allow users to submit content to your website, that other visitors can see, you should consider removing the ability to let them use HTML. Although this will remove a lot of cool things that your users can do, like making heavily customized content, it will prevent your site from a lot of common attacks. With some custom coding you can just remove specific tags from running, but that is beyond the scope of this lesson.&lt;br /&gt;
Just remember, that when allowing users to submit content to your site you are also giving them access to your website. Be sure you take the proper precautions.&lt;br /&gt;
&lt;br /&gt;
&lt;/form&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://webdesigntipstrick.blogspot.com/feeds/1574770056992789003/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://webdesigntipstrick.blogspot.com/2012/07/php-post-get-with-example-tutorial.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4358669149008391889/posts/default/1574770056992789003'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4358669149008391889/posts/default/1574770056992789003'/><link rel='alternate' type='text/html' href='http://webdesigntipstrick.blogspot.com/2012/07/php-post-get-with-example-tutorial.html' title='PHP POST &amp; GET with Example Tutorial'/><author><name>Admin</name><uri>http://www.blogger.com/profile/05350530015134205170</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4358669149008391889.post-5170447682361585777</id><published>2012-07-12T00:02:00.000-07:00</published><updated>2012-07-12T00:02:04.444-07:00</updated><title type='text'>PHP Functions and Arrays &amp; loops with Example Tutorial</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;b&gt;PHP - Functions&lt;/b&gt;&lt;br /&gt;
A function is just a name we give to a block of code that can be executed whenever we need it. This might not seem like that big of an idea, but believe me, when you understand and use functions you will be able to save a ton of time and write code that is much more readable!&lt;br /&gt;
For example, you might have a company motto that you have to display at least once on every webpage. If you don&#39;t, then you get fired! Well, being the savvy PHP programmer you are, you think to yourself, &quot;this sounds like a situation where I might need functions.&quot;&lt;br /&gt;
Tip: Although functions are often thought of as an advanced topic for beginning programmers to learn, if you take it slow and stick with it, functions can be just minor speedbump in your programming career. So don&#39;t give up if you functions confuse you at first!&lt;br /&gt;
&lt;b&gt;Creating Your First PHP Function&lt;/b&gt;&lt;br /&gt;
When you create a function, you first need to give it a name, like myCompanyMotto. It&#39;s with this function name that you will be able to call upon your function, so make it easy to type and understand.&lt;br /&gt;
The actual syntax for creating a function is pretty self-explanatory, but you can be the judge of that. First, you must tell PHP that you want to create a function. You do this by typing the keyword function followed by your function name and some other stuff (which we&#39;ll talk about later).&lt;br /&gt;
Here is how you would make a function called myCompanyMotto. Note: We still have to fill in the code for myCompanyMotto.&lt;br /&gt;
&lt;b&gt;PHP Code:&lt;/b&gt;&lt;br /&gt;
&lt;!--?php&lt;/p--&gt;&lt;br /&gt;
function myCompanyMotto(){&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
Note: Your function name can start with a letter or underscore &quot;_&quot;, but not a number!&lt;br /&gt;
With a properly formatted function in place, we can now fill in the code that we want our function to execute. Do you see the curly braces in the above example &quot;{ }&quot;? These braces define where our function&#39;s code goes. The opening curly brace &quot;{&quot; tells php that the function&#39;s code is starting and a closing curly brace &quot;}&quot; tells PHP that our function is done!&lt;br /&gt;
We want our function to print out the company motto each time it&#39;s called, so that sounds like it&#39;s a job for the echo function!&lt;br /&gt;
PHP Code:&lt;br /&gt;
&lt;!--?php&lt;/p--&gt;&lt;br /&gt;
function myCompanyMotto(){&lt;br /&gt;
echo &quot;We deliver quantity, not quality!&lt;br /&gt;&quot;;&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
That&#39;s it! You have written your first PHP function from scratch! Notice that the code that appears within a function is just the same as any other PHP code.&lt;br /&gt;
&lt;b&gt;Using Your PHP Function&lt;/b&gt;&lt;br /&gt;
Now that you have completed coding your PHP function, it&#39;s time to put it through a test run. Below is a simple PHP script. Let&#39;s do two things: add the function code to it and use the function twice.&lt;br /&gt;
&lt;b&gt;PHP Code:&lt;/b&gt;&lt;br /&gt;
&lt;!--?php&lt;/p--&gt;&lt;br /&gt;
echo &quot;Welcome to Tizag.com &lt;br /&gt;&quot;;&lt;br /&gt;
echo &quot;Well, thanks for stopping by! &lt;br /&gt;&quot;;&lt;br /&gt;
echo &quot;and remember... &lt;br /&gt;&quot;;&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
PHP Code with Function:&lt;br /&gt;
&lt;!--?php&lt;/p--&gt;&lt;br /&gt;
function myCompanyMotto(){&lt;br /&gt;
echo &quot;We deliver quantity, not quality!&lt;br /&gt;&quot;;&lt;br /&gt;
}&lt;br /&gt;
echo &quot;Welcome to Tizag.com &lt;br /&gt;&quot;;&lt;br /&gt;
myCompanyMotto();&lt;br /&gt;
echo &quot;Well, thanks for stopping by! &lt;br /&gt;&quot;;&lt;br /&gt;
echo &quot;and remember... &lt;br /&gt;&quot;;&lt;br /&gt;
myCompanyMotto();&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
Display:&lt;br /&gt;
Welcome to Tizag.com We deliver quantity, not quality! Well, thanks for stopping by! and remember... We deliver quantity, not quality!&lt;br /&gt;
Although this was a simple example, it&#39;s important to understand that there is a lot going on and there are a lot of areas to make errors. When you are creating a function, follow these simple guidelines:&lt;br /&gt;
• Always start your function with the keyword function&lt;br /&gt;
• Remember that your function&#39;s code must be between the &quot;{&quot; and the &quot;}&quot;&lt;br /&gt;
• When you are using your function, be sure you spell the function name correctly&lt;br /&gt;
• Don&#39;t give up!&lt;br /&gt;
&lt;b&gt;PHP Functions - Parameters&lt;/b&gt;&lt;br /&gt;
Another useful thing about functions is that you can send them information that the function can then use. Our first function myCompanyMotto isn&#39;t all that useful because all it does, and ever will do, is print out a single, unchanging string.&lt;br /&gt;
However, if we were to use parameters, then we would be able to add some extra functionality! A parameter appears with the parentheses &quot;( )&quot; and looks just like a normal PHP variable. Let&#39;s create a new function that creates a custom greeting based off of a person&#39;s name.&lt;br /&gt;
Our parameter will be the person&#39;s name and our function will concatenate this name onto a greeting string. Here&#39;s what the code would look like.&lt;br /&gt;
PHP Code with Function:&lt;br /&gt;
&lt;!--?php&lt;/p--&gt;&lt;br /&gt;
function myGreeting($firstName){&lt;br /&gt;
echo &quot;Hello there &quot;. $firstName . &quot;!&lt;br /&gt;&quot;;&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
When we use our myGreeting function we have to send it a string containing someone&#39;s name, otherwise it will break. When you add parameters, you also add more responsibility to you, the programmer! Let&#39;s call our new function a few times with some common first names.&lt;br /&gt;
PHP Code:&lt;br /&gt;
&lt;!--?php&lt;/p--&gt;&lt;br /&gt;
function myGreeting($firstName){&lt;br /&gt;
echo &quot;Hello there &quot;. $firstName . &quot;!&lt;br /&gt;&quot;;&lt;br /&gt;
}&lt;br /&gt;
myGreeting(&quot;Jack&quot;);&lt;br /&gt;
myGreeting(&quot;Ahmed&quot;);&lt;br /&gt;
myGreeting(&quot;Julie&quot;);&lt;br /&gt;
myGreeting(&quot;Charles&quot;);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
Display:&lt;br /&gt;
Hello there Jack! Hello there Ahmed! Hello there Julie! Hello there Charles!&lt;br /&gt;
It is also possible to have multiple parameters in a function. To separate multiple parameters PHP uses a comma &quot;,&quot;. Let&#39;s modify our function to also include last names.&lt;br /&gt;
PHP Code:&lt;br /&gt;
&lt;!--?php&lt;/p--&gt;&lt;br /&gt;
function myGreeting($firstName, $lastName){&lt;br /&gt;
echo &quot;Hello there &quot;. $firstName .&quot; &quot;. $lastName .&quot;!&lt;br /&gt;&quot;;&lt;br /&gt;
}&lt;br /&gt;
myGreeting(&quot;Jack&quot;, &quot;Black&quot;);&lt;br /&gt;
myGreeting(&quot;Ahmed&quot;, &quot;Zewail&quot;);&lt;br /&gt;
myGreeting(&quot;Julie&quot;, &quot;Roberts&quot;);&lt;br /&gt;
myGreeting(&quot;Charles&quot;, &quot;Schwab&quot;);&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
Display:&lt;br /&gt;
Hello there Jack Black! Hello there Ahmed Zewail! Hello there Julie Roberts! Hello there Charles Schwab!&lt;br /&gt;
&lt;b&gt;PHP Functions - Returning Values&lt;/b&gt;&lt;br /&gt;
Besides being able to pass functions information, you can also have them return a value. However, a function can only return one thing, although that thing can be any integer, float, array, string, etc. that you choose!&lt;br /&gt;
How does it return a value though? Well, when the function is used and finishes executing, it sort of changes from being a function name into being a value. To capture this value you can set a variable equal to the function. Something like:&lt;br /&gt;
• $myVar = somefunction();&lt;br /&gt;
Let&#39;s demonstrate this returning of a value by using a simple function that returns the sum of two integers.&lt;br /&gt;
PHP Code:&lt;br /&gt;
&lt;!--?php&lt;/p--&gt;&lt;br /&gt;
function mySum($numX, $numY){&lt;br /&gt;
$total = $numX + $numY;&lt;br /&gt;
return $total;&lt;br /&gt;
}&lt;br /&gt;
$myNumber = 0;&lt;br /&gt;
echo &quot;Before the function, myNumber = &quot;. $myNumber .&quot;&lt;br /&gt;&quot;;&lt;br /&gt;
$myNumber = mySum(3, 4); // Store the result of mySum in $myNumber&lt;br /&gt;
echo &quot;After the function, myNumber = &quot; . $myNumber .&quot;&lt;br /&gt;&quot;;&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
Display:&lt;br /&gt;
Before the function, myNumber = 0 After the function, myNumber = 7&lt;br /&gt;
When we first print out the value of $myNumber it is still set to the original value of 0. However, when we set $myNumber equal to the function mySum, $myNumber is set equal to mySum&#39;s result. In this case, the result was 3 + 4 = 7, which was successfully stored into $myNumber and displayed in the second echo statement!&lt;br /&gt;
&lt;b&gt;PHP Functions - Practice Makes Perfect&lt;/b&gt;&lt;br /&gt;
If you are new to programming, then this lesson might or might not seem like overkill. If you are having a hard time understanding lessons, the best piece of advice would be to do your best the first time, then be sure to come back tomorrow and next week and see if it makes anymore sense. Chances are, after going through this tutorial more than once, with breaks in between, this topic will be mastered.&lt;br /&gt;
&lt;b&gt;PHP - Arrays&lt;/b&gt;&lt;br /&gt;
An array is a data structure that stores one or more values in a single value. For experienced programmers it is important to note that PHP&#39;s arrays are actually maps (each key is mapped to a value).&lt;br /&gt;
PHP - A Numerically Indexed Array&lt;br /&gt;
If this is your first time seeing an array, then you may not quite understand the concept of an array. Imagine that you own a business and you want to store the names of all your employees in a PHP variable. How would you go about this?&lt;br /&gt;
It wouldn&#39;t make much sense to have to store each name in its own variable. Instead, it would be nice to store all the employee names inside of a single variable. This can be done, and we show you how below.&lt;br /&gt;
PHP Code:&lt;br /&gt;
$employee_array[0] = &quot;Bob&quot;;&lt;br /&gt;
$employee_array[1] = &quot;Sally&quot;;&lt;br /&gt;
$employee_array[2] = &quot;Charlie&quot;;&lt;br /&gt;
$employee_array[3] = &quot;Clare&quot;;&lt;br /&gt;
In the above example we made use of the key / value structure of an array. The keys were the numbers we specified in the array and the values were the names of the employees. Each key of an array represents a value that we can manipulate and reference. The general form for setting the key of an array equal to a value is:&lt;br /&gt;
• $array[key] = value;&lt;br /&gt;
If we wanted to reference the values that we stored into our array, the following PHP code would get the job done.&lt;br /&gt;
PHP Code:&lt;br /&gt;
echo &quot;Two of my employees are &quot;&lt;br /&gt;
. $employee_array[0] . &quot; &amp;amp; &quot; . $employee_array[1];&lt;br /&gt;
echo &quot;&lt;br /&gt;Two more employees of mine are &quot;&lt;br /&gt;
. $employee_array[2] . &quot; &amp;amp; &quot; . $employee_array[3];&lt;br /&gt;
Display:&lt;br /&gt;
Two of my employees are Bob &amp;amp; Sally Two more employees of mine are Charlie &amp;amp; Clare&lt;br /&gt;
PHP arrays are quite useful when used in conjunction with loops, which we will talk about in a later lesson. Above we showed an example of an array that made use of integers for the keys (a numerically indexed array). However, you can also specify a string as the key, which is referred to as an associative array.&lt;br /&gt;
&lt;b&gt;PHP - Associative Arrays&lt;/b&gt;&lt;br /&gt;
In an associative array a key is associated with a value. If you wanted to store the salaries of your employees in an array, a numerically indexed array would not be the best choice. Instead, we could use the employees names as the keys in our associative array, and the value would be their respective salary.&lt;br /&gt;
PHP Code:&lt;br /&gt;
$salaries[&quot;Bob&quot;] = 2000;&lt;br /&gt;
$salaries[&quot;Sally&quot;] = 4000;&lt;br /&gt;
$salaries[&quot;Charlie&quot;] = 600;&lt;br /&gt;
$salaries[&quot;Clare&quot;] = 0;&lt;br /&gt;
echo &quot;Bob is being paid - $&quot; . $salaries[&quot;Bob&quot;] . &quot;&lt;br /&gt;&quot;;&lt;br /&gt;
echo &quot;Sally is being paid - $&quot; . $salaries[&quot;Sally&quot;] . &quot;&lt;br /&gt;&quot;;&lt;br /&gt;
echo &quot;Charlie is being paid - $&quot; . $salaries[&quot;Charlie&quot;] . &quot;&lt;br /&gt;&quot;;&lt;br /&gt;
echo &quot;Clare is being paid - $&quot; . $salaries[&quot;Clare&quot;];&lt;br /&gt;
Display:&lt;br /&gt;
Bob is being paid - $2000 Sally is being paid - $4000 Charlie is being paid - $600 Clare is being paid - $0&lt;br /&gt;
Once again, the usefulness of arrays will become more apparent once you have knowledge of for and while loops.&lt;br /&gt;
&lt;b&gt;PHP - While Loop&lt;/b&gt;&lt;br /&gt;
Repetitive tasks are always a burden to us. Deleting spam email, sealing 50 envelopes, and going to work are all examples of tasks that are repeated. The nice thing about programming is that you can avoid such repetitive tasks with a little bit of extra thinking. Most often these repetitive tasks are conquered in the loop.&lt;br /&gt;
The idea of a loop is to do something over and over again until the task has been completed. Before we show a real example of when you might need one, let&#39;s go over the structure of the PHP while loop.&lt;br /&gt;
&lt;b&gt;Simple While Loop Example&lt;/b&gt;&lt;br /&gt;
The function of the while loop is to do a task over and over as long as the specified conditional statement is true. This logical check is the same as the one that appears in a PHP if statement to determine if it is true or false. Here is the basic structure of a PHP while loop:&lt;br /&gt;
Pseudo PHP Code:&lt;br /&gt;
while ( conditional statement is true){&lt;br /&gt;
//do this code;&lt;br /&gt;
}&lt;br /&gt;
This isn&#39;t valid PHP code, but it displays how the while loop is structured. Here is the break down of how a while loop functions when your script is executing:&lt;br /&gt;
1. The conditional statement is checked. If it is true, then (2) occurs. If it is false, then (4) occurs.&lt;br /&gt;
2. The code within the while loop is executed.&lt;br /&gt;
3. The process starts again at (1). Effectively &quot;looping&quot; back.&lt;br /&gt;
4. If the conditional statement is false, then the code within is not executed and there is no more looping. The code following the while loop is then executed like normal.&lt;br /&gt;
A Real While Loop Example&lt;br /&gt;
Imagine that you are running an art supply store. You would like to print out the price chart for number of brushes and total cost. You sell brushes at a flat rate, but would like to display how much different quantities would cost. This will save your customers from having to do the mental math themselves.&lt;br /&gt;
You know that a while loop would be perfect for this repetitive and boring task. Here is how to go about doing it.&lt;br /&gt;
Pseudo PHP Code:&lt;br /&gt;
$brush_price = 5;&lt;br /&gt;
$counter = 10;&lt;br /&gt;
echo &quot;&lt;br /&gt;
&quot;;&lt;br /&gt;
echo &quot;&lt;br /&gt;
&quot;;&lt;br /&gt;
echo &quot;&lt;br /&gt;
&quot;;&lt;br /&gt;
while ( $counter &amp;lt;= 100 ) {&lt;br /&gt;
echo &quot;&lt;br /&gt;
&quot;;&lt;br /&gt;
$counter = $counter + 10;&lt;br /&gt;
}&lt;br /&gt;
echo &quot;&lt;br /&gt;
&lt;table align=&quot;\&amp;quot;center\&amp;quot;&quot; border=&quot;\&amp;quot;1\&amp;quot;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Quantity&lt;/th&gt;&lt;th&gt;Price&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&quot;;&lt;br /&gt;
echo $counter;&lt;br /&gt;
echo &quot;&lt;/td&gt;&lt;td&gt;&quot;;&lt;br /&gt;
echo $brush_price * $counter;&lt;br /&gt;
echo &quot;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&quot;;&lt;br /&gt;
Display:&lt;br /&gt;
Quantity&lt;br /&gt;
Price&lt;br /&gt;
10&lt;br /&gt;
50&lt;br /&gt;
20&lt;br /&gt;
100&lt;br /&gt;
30&lt;br /&gt;
150&lt;br /&gt;
40&lt;br /&gt;
200&lt;br /&gt;
50&lt;br /&gt;
250&lt;br /&gt;
60&lt;br /&gt;
300&lt;br /&gt;
70&lt;br /&gt;
350&lt;br /&gt;
80&lt;br /&gt;
400&lt;br /&gt;
90&lt;br /&gt;
450&lt;br /&gt;
100&lt;br /&gt;
500&lt;br /&gt;
Pretty neat, huh? The loop created a new table row and its respective entries for each quantity, until our counter variable grew past the size of 100. When it grew past 100 our conditional statement failed and the loop stopped being used. Let&#39;s review what is going on.&lt;br /&gt;
1. We first made a $brush_price and $counter variable and set them equal to our desired values.&lt;br /&gt;
2. The table was set up with the beginning table tag and the table headers.&lt;br /&gt;
3. The while loop conditional statement was checked, and $counter (10) was indeed smaller or equal to 100.&lt;br /&gt;
4. The code inside the while loop was executed, creating a new table row for the price of 10 brushes.&lt;br /&gt;
5. We then added 10 to $counter to bring the value to 20.&lt;br /&gt;
6. The loop started over again at step 3, until $counter grew larger than 100.&lt;br /&gt;
7. After the loop had completed, we ended the table.&lt;br /&gt;
You may have noticed that we placed slashes infront the quotations in the first echo statement. You have to place slashes before quotations if you do not want the quotation to act as the end of the echo statement. This is called escaping a character and it is discussed in our PHP Strings lesson.&lt;br /&gt;
With proper use of loops you can complete large tasks with great ease.&lt;br /&gt;
PHP - For Loop&lt;br /&gt;
The for loop is simply a while loop with a bit more code added to it. The common tasks that are covered by a for loop are:&lt;br /&gt;
1. Set a counter variable to some initial value.&lt;br /&gt;
2. Check to see if the conditional statement is true.&lt;br /&gt;
3. Execute the code within the loop.&lt;br /&gt;
4. Increment a counter at the end of each iteration through the loop.&lt;br /&gt;
The for loop allows you to define these steps in one easy line of code. It may seem to have a strange form, so pay close attention to the syntax used!&lt;br /&gt;
For Loop Example&lt;br /&gt;
Let us take the example from the while loop lesson and see how it could be done in a for loop. The basic structure of the for loop is as follows:&lt;br /&gt;
Pseudo PHP Code:&lt;br /&gt;
for ( initialize a counter; conditional statement; increment a counter){&lt;br /&gt;
do this code;&lt;br /&gt;
}&lt;br /&gt;
Notice how all the steps of the loop are taken care of in the for loop statement. Each step is separated by a semicolon: initiliaze counter, conditional statement, and the counter increment. A semicolon is needed because these are separate expressions. However, notice that a semicolon is not needed after the &quot;increment counter&quot; expression.&lt;br /&gt;
Here is the example of the brush prices done with a for loop .&lt;br /&gt;
PHP Code:&lt;br /&gt;
$brush_price = 5;&lt;br /&gt;
echo &quot;&lt;br /&gt;
&quot;;&lt;br /&gt;
echo &quot;&lt;br /&gt;
&quot;;&lt;br /&gt;
echo &quot;&lt;br /&gt;
&quot;;&lt;br /&gt;
for ( $counter = 10; $counter &amp;lt;= 100; $counter += 10) {&lt;br /&gt;
echo &quot;&lt;br /&gt;
&quot;;&lt;br /&gt;
}&lt;br /&gt;
echo &quot;&lt;br /&gt;
&lt;table align=&quot;\&amp;quot;center\&amp;quot;&quot; border=&quot;\&amp;quot;1\&amp;quot;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;th&gt;Quantity&lt;/th&gt;&lt;th&gt;Price&lt;/th&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;&quot;;&lt;br /&gt;
echo $counter;&lt;br /&gt;
echo &quot;&lt;/td&gt;&lt;td&gt;&quot;;&lt;br /&gt;
echo $brush_price * $counter;&lt;br /&gt;
echo &quot;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&quot;;&lt;br /&gt;
Display:&lt;br /&gt;
Quantity&lt;br /&gt;
Price&lt;br /&gt;
10&lt;br /&gt;
50&lt;br /&gt;
20&lt;br /&gt;
100&lt;br /&gt;
30&lt;br /&gt;
150&lt;br /&gt;
40&lt;br /&gt;
200&lt;br /&gt;
50&lt;br /&gt;
250&lt;br /&gt;
60&lt;br /&gt;
300&lt;br /&gt;
70&lt;br /&gt;
350&lt;br /&gt;
80&lt;br /&gt;
400&lt;br /&gt;
90&lt;br /&gt;
450&lt;br /&gt;
100&lt;br /&gt;
500&lt;br /&gt;
It is important to note that both the for loop and while loop implementation of the price chart table are both OK at getting the job done. However, the for loop is somewhat more compact and would be preferable in this situation. In later lessons we will see where the while loop should be used instead of the for loop.&lt;br /&gt;
&lt;b&gt;PHP For Each Loop&lt;/b&gt;&lt;br /&gt;
Imagine that you have an associative array that you want to iterate through. PHP provides an easy way to use every element of an array with the Foreach statement.&lt;br /&gt;
In plain english this statement will do the following:&lt;br /&gt;
• For each item in the specified array execute this code.&lt;br /&gt;
While a For Loop and While Loop will continue until some condition fails, the For Each loop will continue until it has gone through every item in the array.&lt;br /&gt;
&lt;b&gt;PHP For Each: Example&lt;/b&gt;&lt;br /&gt;
We have an associative array that stores the names of people in our company as the keys with the values being their age. We want to know how old everyone is at work so we use a Foreach loop to print out everyone&#39;s name and age.&lt;br /&gt;
PHP Code:&lt;br /&gt;
$employeeAges;&lt;br /&gt;
$employeeAges[&quot;Lisa&quot;] = &quot;28&quot;;&lt;br /&gt;
$employeeAges[&quot;Jack&quot;] = &quot;16&quot;;&lt;br /&gt;
$employeeAges[&quot;Ryan&quot;] = &quot;35&quot;;&lt;br /&gt;
$employeeAges[&quot;Rachel&quot;] = &quot;46&quot;;&lt;br /&gt;
$employeeAges[&quot;Grace&quot;] = &quot;34&quot;;&lt;br /&gt;
foreach( $employeeAges as $key =&amp;gt; $value){&lt;br /&gt;
echo &quot;Name: $key, Age: $value &lt;br /&gt;&quot;;&lt;br /&gt;
}&lt;br /&gt;
Display:&lt;br /&gt;
Name: Lisa, Age: 28 Name: Jack, Age: 16 Name: Ryan, Age: 35 Name: Rachel, Age: 46 Name: Grace, Age: 34&lt;br /&gt;
The syntax of the foreach statement is a little strange, so let&#39;s talk about it some.&lt;br /&gt;
Foreach Syntax: $something as $key =&amp;gt; $value&lt;br /&gt;
This crazy statement roughly translates into: For each element of the $employeeAges associative array I want to refer to the key as $key and the value as $value.&lt;br /&gt;
The operator &quot;=&amp;gt;&quot; represents the relationship between a key and value. You can imagine that the key points =&amp;gt; to the value. In our example we named the key $key and the value $value. However, it might be easier to think of it as $name and $age. Below our example does this and notice how the output is identical because we only changed the variable names that refer to the keys and values.&lt;br /&gt;
PHP Code:&lt;br /&gt;
$employeeAges;&lt;br /&gt;
$employeeAges[&quot;Lisa&quot;] = &quot;28&quot;;&lt;br /&gt;
$employeeAges[&quot;Jack&quot;] = &quot;16&quot;;&lt;br /&gt;
$employeeAges[&quot;Ryan&quot;] = &quot;35&quot;;&lt;br /&gt;
$employeeAges[&quot;Rachel&quot;] = &quot;46&quot;;&lt;br /&gt;
$employeeAges[&quot;Grace&quot;] = &quot;34&quot;;&lt;br /&gt;
foreach( $employeeAges as $name =&amp;gt; $age){&lt;br /&gt;
echo &quot;Name: $name, Age: $age &lt;br /&gt;&quot;;&lt;br /&gt;
}&lt;br /&gt;
Display:&lt;br /&gt;
Name: Lisa, Age: 28 Name: Jack, Age: 16 Name: Ryan, Age: 35 Name: Rachel, Age: 46 Name: Grace, Age: 34&lt;br /&gt;
&lt;b&gt;PHP - Do While Loop&lt;/b&gt;&lt;br /&gt;
A &quot;do while&quot; loop is a slightly modified version of the while loop. If you recal from one of the previous lessons on While Loops the conditional statement is checked comes back true then the code within the while loop is executed. If the conditional statement is false then the code within the loop is not executed.&lt;br /&gt;
On the other hand, a do-while loop always executes its block of code at least once. This is because the conditional statement is not checked until after the contained code has been executed.&lt;br /&gt;
&lt;b&gt;PHP - While Loop and Do While Loop Contrast&lt;/b&gt;&lt;br /&gt;
A simple example that illustrates the difference between these two loop types is a conditional statement that is always false. First the while loop:&lt;br /&gt;
&lt;b&gt;PHP Code:&lt;/b&gt;&lt;br /&gt;
$cookies = 0;&lt;br /&gt;
while($cookies &amp;gt; 1){&lt;br /&gt;
echo &quot;Mmmmm...I love cookies! *munch munch munch*&quot;;&lt;br /&gt;
}&lt;br /&gt;
Display:&lt;br /&gt;
As you can see, this while loop&#39;s conditional statement failed (0 is not greater than 1), which means the code within the while loop was not executed. Now, can you guess what will happen with a do-while loop?&lt;br /&gt;
PHP Code:&lt;br /&gt;
$cookies = 0;&lt;br /&gt;
do {&lt;br /&gt;
echo &quot;Mmmmm...I love cookies! *munch munch munch*&quot;;&lt;br /&gt;
} while ($cookies &amp;gt; 1);&lt;br /&gt;
Display:&lt;br /&gt;
Mmmmm...I love cookies! *munch munch munch*&lt;br /&gt;
The code segment &quot;Mmmm...I love cookies!&quot; was executed even though the conditional statement was false. This is because a do-while loop first do&#39;s and secondly checks the while condition!&lt;br /&gt;
Chances are you will not need to use a do while loop in most of your PHP programming, but it is good to know it&#39;s there!&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://webdesigntipstrick.blogspot.com/feeds/5170447682361585777/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://webdesigntipstrick.blogspot.com/2012/07/php-functions-and-arrays-loops-with.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4358669149008391889/posts/default/5170447682361585777'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4358669149008391889/posts/default/5170447682361585777'/><link rel='alternate' type='text/html' href='http://webdesigntipstrick.blogspot.com/2012/07/php-functions-and-arrays-loops-with.html' title='PHP Functions and Arrays &amp; loops with Example Tutorial'/><author><name>Admin</name><uri>http://www.blogger.com/profile/05350530015134205170</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4358669149008391889.post-4332346779134072141</id><published>2012-07-11T23:59:00.007-07:00</published><updated>2012-07-11T23:59:38.672-07:00</updated><title type='text'>PHP Statements wit example Tutorial</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;b&gt;If Statement&lt;/b&gt;&lt;br /&gt;
The PHP if statement is very similar to other programming languages use of the if statement, but for those who are not familiar with it, picture the following:&lt;br /&gt;
Think about the decisions you make before you go to sleep. If you have something to do the next day, say go to work, school, or an appointment, then you will set your alarm clock to wake you up. Otherwise, you will sleep in as long as you like!&lt;br /&gt;
This simple kind of if/then statement is very common in every day life and also appears in programming quite often. Whenever you want to make a decision given that something is true (you have something to do tomorrow) and be sure that you take the appropriate action, you are using an if/then relationship.&lt;br /&gt;
&lt;b&gt;The PHP If Statement&lt;/b&gt;&lt;br /&gt;
The if statement is necessary for most programming, thus it is important in PHP. Imagine that on January 1st you want to print out &quot;Happy New Year!&quot; at the top of your personal web page. With the use of PHP if statements you could have this process automated, months in advance, occuring every year on January 1st.&lt;br /&gt;
This idea of planning for future events is something you would never have had the opportunity of doing if you had just stuck with HTML.&lt;br /&gt;
&lt;b&gt;If Statement Example&lt;/b&gt;&lt;br /&gt;
The &quot;Happy New Year&quot; example would be a little difficult for you to do right now, so let us instead start off with the basics of the if statement. The PHP if statement tests to see if a value is true, and if it is a segment of code will be executed. See the example below for the form of a PHP if statement.&lt;br /&gt;
PHP Code:&lt;br /&gt;
$my_name = &quot;someguy&quot;;&lt;br /&gt;
if ( $my_name == &quot;someguy&quot; ) {&lt;br /&gt;
echo &quot;Your name is someguy!&lt;br /&gt;&quot;;&lt;br /&gt;
}&lt;br /&gt;
echo &quot;Welcome to my homepage!&quot;;&lt;br /&gt;
Display:&lt;br /&gt;
Your name is someguy! Welcome to my homepage!&lt;br /&gt;
Did you get that we were comparing the variable $my_name with &quot;someguy&quot; to see if they were equal? In PHP you use the double equal sign (==) to compare values. Additionally, notice that because the if statement turned out to be true, the code segment was executed, printing out &quot;Your name is someguy!&quot;. Let&#39;s go a bit more in-depth into this example to iron out the details.&lt;br /&gt;
• We first set the variable $my_name equal to &quot;someguy&quot;.&lt;br /&gt;
• We next used a PHP if statement to check if the value contained in the variable $my_name was equal to &quot;someguy&quot;&lt;br /&gt;
• The comparison between $my_name and &quot;someguy&quot; was done with a double equal sign &quot;==&quot;, not a single equals&quot;=&quot;! A single equals is for assigning a value to a variable, while a double equals is for checking if things are equal.&lt;br /&gt;
• Translated into english the PHP statement ( $my_name == &quot;someguy&quot; ) is ( $my_name is equal to &quot;someguy&quot; ).&lt;br /&gt;
• $my_name is indeed equal to &quot;someguy&quot; so the echo statement is executed.&lt;br /&gt;
&lt;b&gt;A False If Statement&lt;/b&gt;&lt;br /&gt;
Let us now see what happens when a PHP if statement is not true, in other words, false. Say that we changed the above example to:&lt;br /&gt;
PHP Code:&lt;br /&gt;
$my_name = &quot;anotherguy&quot;;&lt;br /&gt;
if ( $my_name == &quot;someguy&quot; ) {&lt;br /&gt;
echo &quot;Your name is someguy!&lt;br /&gt;&quot;;&lt;br /&gt;
}&lt;br /&gt;
echo &quot;Welcome to my homepage!&quot;;&lt;br /&gt;
Display:&lt;br /&gt;
Welcome to my homepage!&lt;br /&gt;
Here the variable contained the value &quot;anotherguy&quot;, which is not equal to &quot;someguy&quot;. The if statement evaluated to false, so the code segment of the if statement was not executed. When used properly, the if statement is a powerful tool to have in your programming arsenal!&lt;br /&gt;
&lt;b&gt;If/Else Conditional Statment&lt;/b&gt;&lt;br /&gt;
Has someone ever told you, &quot;if you work hard, then you will succeed&quot;? And what happens if you do not work hard? Well, you fail! This is an example of an if/else conditional statement.&lt;br /&gt;
• If you work hard then you will succeed.&lt;br /&gt;
• Else, if you do not work hard, then you will fail.&lt;br /&gt;
How does this translate into something useful for PHP developers? Well consider this:&lt;br /&gt;
Someone comes to your website and you want to ask this visitor her name if it is her first time coming to your site. With an if statement this is easy. Simply have a conditional statement to check, &quot;are you visiting for the first time&quot;. If the condition is true, then take them to the &quot;Insert Your Name&quot; page, else let her view the website as normal because you have already asked her for her name in the past.&lt;br /&gt;
&lt;b&gt;If/Else an Example&lt;/b&gt;&lt;br /&gt;
Using these conditional statements can add a new layers of &quot;cool&quot; to your website. Here&#39;s the basic form of an if/else statement in PHP.&lt;br /&gt;
PHP Code:&lt;br /&gt;
$number_three = 3;&lt;br /&gt;
if ( $number_three == 3 ) {&lt;br /&gt;
echo &quot;The if statement evaluated to true&quot;;&lt;br /&gt;
} else {&lt;br /&gt;
echo &quot;The if statement evaluated to false&quot;;&lt;br /&gt;
}&lt;br /&gt;
Display:&lt;br /&gt;
The if statement evaluated to true&lt;br /&gt;
This is a lot to digest in one sitting, so let us step through the code, line by line.&lt;br /&gt;
• We first made a PHP variable called $number_three and set it equal to 3.&lt;br /&gt;
• In this example we compared a variable to an integer value. To do such a comparison we use &quot;==&quot;, which in English means &quot;Is Equal To&quot;.&lt;br /&gt;
• $number_three is indeed Equal To 3 and so this statement will evaluate to true.&lt;br /&gt;
• All code that is contained between the opening curly brace &quot;{&quot; that follows the if statement and the closing curly brace &quot;}&quot; will be executed when the if statement is true.&lt;br /&gt;
• The code contained within the else segment will not used.&lt;br /&gt;
&lt;b&gt;Execute Else Code with False&lt;/b&gt;&lt;br /&gt;
On the other hand, if the if statement was false, then the code contained in the else segment would have been executed. Note that the code within the if and else cannot both be executed, as the if statement cannot evaluate to both true and false at one time! Here is what would happen if we changed to $number_three to anything besides the number 3.&lt;br /&gt;
PHP Code:&lt;br /&gt;
$number_three = 421;&lt;br /&gt;
if ( $number_three == 3 ) {&lt;br /&gt;
echo &quot;The if statement evaluated to true&quot;;&lt;br /&gt;
} else {&lt;br /&gt;
echo &quot;The if statement evaluated to false&quot;;&lt;br /&gt;
}&lt;br /&gt;
Display:&lt;br /&gt;
The if statement evaluated to false&lt;br /&gt;
The variable was set to 421, which is not equal to 3 and the if statement was false. As you can see, the code segment contained within the else was used in this case.&lt;br /&gt;
&lt;b&gt;PHP - Elseif&lt;/b&gt;&lt;br /&gt;
An if/else statement is great if you only need to check for one condition. However, what would you do if you wanted to check if your $employee variable was the company owner Bob, the Vice President Ms. Tanner, or a regular employee? To check for these different conditions you would need the elseif statement.&lt;br /&gt;
&lt;b&gt;PHP - Elseif What is it?&lt;/b&gt;&lt;br /&gt;
An if statement is made up of the keyword &quot;if&quot; and a conditional statement (i.e. $name == &quot;Ted&quot;). Just like an if statement, an elseif statement also contains a conditional statement, but it must be preceded by an if statement. You cannot have an elseif statement without first having an if statement.&lt;br /&gt;
When PHP evaluates your If...elseif...else statement it will first see if the If statement is true. If that tests comes out false it will then check the first elseif statement. If that is false it will either check the next elseif statement, or if there are no more elseif statements, it will evaluate the else segment, if one exists (I don&#39;t think I&#39;ve ever used the word &quot;if&quot; so much in my entire life!). Let&#39;s take a look at a real world example.&lt;br /&gt;
&lt;b&gt;PHP - Using Elseif with If...Else&lt;/b&gt;&lt;br /&gt;
Let&#39;s start out with the base case. Imagine we have a simpler version of the problem described above. We simply want to find out if the employee is the Vice President Ms. Tanner. We only need an if else statement for this part of the example.&lt;br /&gt;
PHP Code:&lt;br /&gt;
$employee = &quot;Bob&quot;;&lt;br /&gt;
if($employee == &quot;Ms. Tanner&quot;){&lt;br /&gt;
echo &quot;Hello Ma&#39;am&quot;;&lt;br /&gt;
} else {&lt;br /&gt;
echo &quot;Morning&quot;;&lt;br /&gt;
}&lt;br /&gt;
Now, if we wanted to also check to see if the big boss Bob was the employee we need to insert an elseif clause.&lt;br /&gt;
PHP Code:&lt;br /&gt;
$employee = &quot;Bob&quot;;&lt;br /&gt;
if($employee == &quot;Ms. Tanner&quot;){&lt;br /&gt;
echo &quot;Hello Ma&#39;am&quot;;&lt;br /&gt;
} elseif($employee == &quot;Bob&quot;){&lt;br /&gt;
echo &quot;Good Morning Sir!&quot;;&lt;br /&gt;
}else {&lt;br /&gt;
echo &quot;Morning&quot;;&lt;br /&gt;
}&lt;br /&gt;
Display:&lt;br /&gt;
Good Morning Sir!&lt;br /&gt;
PHP first checked to see if $employee was equal to &quot;Ms. Tanner&quot;, which evaluated to false. Next, PHP checked the first elseif statement. $employee did in fact equal &quot;Bob&quot; so the phrase &quot;Good Morning Sir!&quot; was printed out. If we wanted to check for more employee names we could insert more elseif statements!&lt;br /&gt;
Remember that an elseif statement cannot be used unless it is preceded by an if statement!&lt;br /&gt;
&lt;b&gt;PHP Switch Statement&lt;/b&gt;&lt;br /&gt;
In the previous lessons we covered the various elements that make up an If Statement in PHP. However, there are times when an if statement is not the most efficient way to check for certain conditions.&lt;br /&gt;
For example we might have a variable that stores travel destinations and you want to pack according to this destination variable. In this example you might have 20 different locations that you would have to check with a nasty long block of If/ElseIf/ElseIf/ElseIf/... statements. This doesn&#39;t sound like much fun to code, let&#39;s see if we can do something different.&lt;br /&gt;
&lt;b&gt;PHP Switch Statement: Speedy Checking&lt;/b&gt;&lt;br /&gt;
With the use of the switch statement you can check for all these conditions at once, and the great thing is that it is actually more efficient programming to do this. A true win-win situation!&lt;br /&gt;
The way the Switch statement works is it takes a single variable as input and then checks it against all the different cases you set up for that switch statement. Instead of having to check that variable one at a time, as it goes through a bunch of If Statements, the Switch statement only has to check one time.&lt;br /&gt;
&lt;b&gt;PHP Switch Statement Example&lt;/b&gt;&lt;br /&gt;
In our example the single variable will be $destination and the cases will be: Las Vegas, Amsterdam, Egypt, Tokyo, and the Caribbean Islands.&lt;br /&gt;
PHP Code:&lt;br /&gt;
$destination = &quot;Tokyo&quot;;&lt;br /&gt;
echo &quot;Traveling to $destination&lt;br /&gt;&quot;;&lt;br /&gt;
switch ($destination){&lt;br /&gt;
case &quot;Las Vegas&quot;:&lt;br /&gt;
echo &quot;Bring an extra $500&quot;;&lt;br /&gt;
break;&lt;br /&gt;
case &quot;Amsterdam&quot;:&lt;br /&gt;
echo &quot;Bring an open mind&quot;;&lt;br /&gt;
break;&lt;br /&gt;
case &quot;Egypt&quot;:&lt;br /&gt;
echo &quot;Bring 15 bottles of SPF 50 Sunscreen&quot;;&lt;br /&gt;
break;&lt;br /&gt;
case &quot;Tokyo&quot;:&lt;br /&gt;
echo &quot;Bring lots of money&quot;;&lt;br /&gt;
break;&lt;br /&gt;
case &quot;Caribbean Islands&quot;:&lt;br /&gt;
echo &quot;Bring a swimsuit&quot;;&lt;br /&gt;
break;&lt;br /&gt;
}&lt;br /&gt;
Display:&lt;br /&gt;
Traveling to Tokyo Bring lots of money&lt;br /&gt;
The value of $destination was Tokyo, so when PHP performed the switch operating on $destination in immediately did a search for a case with the value of &quot;Tokyo&quot;. It found it and proceeded to execute the code that existed within that segment.&lt;br /&gt;
You might have noticed how each case contains a break; at the end of its code area. This break prevents the other cases from being executed. If the above example did not have any break statements then all the cases that follow Tokyo would have been executed as well. Use this knowledge to enhance the power of your &lt;b&gt;switch statements!&lt;/b&gt;&lt;br /&gt;
The form of the switch statement is rather unique, so spend some time reviewing it before moving on. Note: Beginning programmers should always include the break; to avoid any unnecessary confusion.&lt;br /&gt;
&lt;b&gt;PHP Switch Statement: Default Case&lt;/b&gt;&lt;br /&gt;
You may have noticed the lack of a place for code when the variable doesn&#39;t match our condition. The if statement has the else clause and the switch statement has the default case.&lt;br /&gt;
It&#39;s usually a good idea to always include the default case in all your switch statements. Below is a variation of our example that will result in none of the cases being used causing our switch statement to fall back and use the default case. Note: there is no case before default.&lt;br /&gt;
&lt;b&gt;PHP Code&lt;/b&gt;:&lt;br /&gt;
$destination = &quot;New York&quot;;&lt;br /&gt;
echo &quot;Traveling to $destination&lt;br /&gt;&quot;;&lt;br /&gt;
switch ($destination){&lt;br /&gt;
case &quot;Las Vegas&quot;:&lt;br /&gt;
echo &quot;Bring an extra $500&quot;;&lt;br /&gt;
break;&lt;br /&gt;
case &quot;Amsterdam&quot;:&lt;br /&gt;
echo &quot;Bring an open mind&quot;;&lt;br /&gt;
break;&lt;br /&gt;
case &quot;Egypt&quot;:&lt;br /&gt;
echo &quot;Bring 15 bottles of SPF 50 Sunscreen&quot;;&lt;br /&gt;
break;&lt;br /&gt;
case &quot;Tokyo&quot;:&lt;br /&gt;
echo &quot;Bring lots of money&quot;;&lt;br /&gt;
break;&lt;br /&gt;
case &quot;Caribbean Islands&quot;:&lt;br /&gt;
echo &quot;Bring a swimsuit&quot;;&lt;br /&gt;
break;&lt;br /&gt;
default:&lt;br /&gt;
echo &quot;Bring lots of underwear!&quot;;&lt;br /&gt;
break;&lt;br /&gt;
}&lt;br /&gt;
Display:&lt;br /&gt;
Traveling to New York Bring lots of underwear!&lt;br /&gt;
Using PHP With HTML Forms&lt;br /&gt;
It is time to apply the knowledge you have obtained thus far and put it to real use. A very common application of PHP is to have an HTML form gather information from a website&#39;s visitor and then use PHP to do process that information. In this lesson we will simulate a small business&#39;s website that is implementing a very simple order form.&lt;br /&gt;
Imagine we are an art supply store that sells brushes, paint, and erasers. To gather order information from our prospective customers we will have to make a page with an HTML form to gather the customer&#39;s order.&lt;br /&gt;
Note: This is an oversimplified example to educate you how to use PHP to process HTML form information. This example is not intended nor advised to be used on a real business website.&lt;br /&gt;
Creating the HTML Form&lt;br /&gt;
If you need a refresher on how to properly make an HTML form, check out the HTML Form Lesson before continuing on.&lt;br /&gt;
We first create an HTML form that will let our customer choose what they would like to purchase. This file should be saved as &quot;order.html&quot;&lt;br /&gt;
.&lt;br /&gt;
order.html Code:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;
Tizag Art Supply Order Form&lt;/h4&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;form&gt;
&lt;br /&gt;
&lt;select&gt;&lt;option&gt;Paint&lt;/option&gt;&lt;option&gt;Brushes&lt;/option&gt;&lt;option&gt;Erasers&lt;/option&gt;&lt;/select&gt;&lt;br /&gt;
Quantity: &lt;input type=&quot;text&quot; /&gt;&lt;br /&gt;
&lt;input type=&quot;submit&quot; /&gt;&lt;br /&gt;
&lt;/form&gt;
&lt;br /&gt;
&lt;br /&gt;
Display:&lt;br /&gt;
Tizag Art Supply Order Form PaintQuantity: Submit Query&lt;br /&gt;
Remember to review HTML Forms if you do not understand any of the above HTML code. Next we must alter our HTML form to specify the PHP page we wish to send this information to. Also, we set the method to &quot;post&quot;.&lt;br /&gt;
order.html Code:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;
Tizag Art Supply Order Form&lt;/h4&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;form action=&quot;process.php&quot; method=&quot;post&quot;&gt;
&lt;br /&gt;
&lt;select name=&quot;item&quot;&gt;&lt;option&gt;Paint&lt;/option&gt;&lt;option&gt;Brushes&lt;/option&gt;&lt;option&gt;Erasers&lt;/option&gt;&lt;/select&gt;&lt;br /&gt;
Quantity: &lt;input name=&quot;quantity&quot; type=&quot;text&quot; /&gt;&lt;br /&gt;
&lt;input type=&quot;submit&quot; /&gt;&lt;br /&gt;
&lt;/form&gt;
&lt;br /&gt;
&lt;br /&gt;
Now that our &quot;order.html&quot; is complete, let us continue on and create the &quot;process.php&quot; file which will process the HTML form information.&lt;br /&gt;
PHP Form Processor&lt;br /&gt;
We want to get the &quot;item&quot; and &quot;quantity&quot; inputs that we have specified in our HTML form. Using an associate array (this term is explained in the array lesson), we can get this information from the $_POST associative array.&lt;br /&gt;
The proper way to get this information would be to create two new variables, $item and $quantity and set them equal to the values that have been &quot;posted&quot;. The name of this file is &quot;process.php&quot;.&lt;br /&gt;
process.php Code:&lt;br /&gt;
&lt;br /&gt;
&lt;!--?php&lt;/p--&gt;&lt;br /&gt;
$quantity = $_POST[&#39;quantity&#39;];&lt;br /&gt;
$item = $_POST[&#39;item&#39;];&lt;br /&gt;
echo &quot;You ordered &quot;. $quantity . &quot; &quot; . $item . &quot;.&lt;br /&gt;&quot;;&lt;br /&gt;
echo &quot;Thank you for ordering from Tizag Art Supplies!&quot;;&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you probably noticed, the name in $_POST[&#39;name&#39;] corresponds to the name that we specified in our HTML form.&lt;br /&gt;
Now try uploading the &quot;order.html&quot; and &quot;process.php&quot; files to a PHP enabled server and test them out. If someone selected the item brushes and specified a quantity of 6, then the following would be displayed on &quot;process.php&quot;:&lt;br /&gt;
process.php Code:&lt;br /&gt;
You ordered 6 brushes.&lt;br /&gt;
Thank you for ordering from Tizag Art Supplies!&lt;br /&gt;
PHP &amp;amp; HTML Form Review&lt;br /&gt;
A lot of things were going on in this example. Let us step through it to be sure you understand what was going on.&lt;br /&gt;
1. We first created an HTML form &quot;order.html&quot; that had two input fields specified, &quot;item&quot; and &quot;quantity&quot;.&lt;br /&gt;
2. We added two attributes to the form tag to point to &quot;process.php&quot; and set the method to &quot;post&quot;.&lt;br /&gt;
3. We had &quot;process.php&quot; get the information that was posted by setting new variables equal to the values in the $_POST associative array.&lt;br /&gt;
4. We used the PHP echo function to output the customers order.&lt;br /&gt;
Remember, this lesson is only to teach you how to use PHP to get information from HTML forms. The example on this page should not be used for a real business.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://webdesigntipstrick.blogspot.com/feeds/4332346779134072141/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://webdesigntipstrick.blogspot.com/2012/07/php-statements-wit-example-tutorial.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4358669149008391889/posts/default/4332346779134072141'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4358669149008391889/posts/default/4332346779134072141'/><link rel='alternate' type='text/html' href='http://webdesigntipstrick.blogspot.com/2012/07/php-statements-wit-example-tutorial.html' title='PHP Statements wit example Tutorial'/><author><name>Admin</name><uri>http://www.blogger.com/profile/05350530015134205170</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4358669149008391889.post-5390397893914879448</id><published>2012-07-11T23:57:00.001-07:00</published><updated>2012-07-11T23:57:10.203-07:00</updated><title type='text'>PHP Include Function with example Tutorial</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;b&gt;Include Function&lt;/b&gt;&lt;br /&gt;
Without understanding much about the details of PHP, you can save yourself a great deal of time with the use of the PHP include function. The include function takes a file name and simply inserts that file&#39;s contents into the script that calls used the include function.&lt;br /&gt;
Why is this a cool thing? Well, first of all, this means that you can type up a common header or menu file that you want all your web pages to include. When you add a new page to your site, instead of having to update the links on several web pages, you can simply change the Menu file.&lt;br /&gt;
An Include Example&lt;br /&gt;
Say we wanted to create a common menu file that all our pages will use. A common practice for naming files that are to be included is to use the &quot;.php&quot; extension. Since we want to create a common menu let&#39;s save it as &quot;menu.php&quot;.&lt;br /&gt;
menu.php Code:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.example.com/index.php&quot;&gt;Home&lt;/a&gt; -&lt;br /&gt;
&lt;a href=&quot;http://www.example.com/about.php&quot;&gt;About Us&lt;/a&gt; -&lt;br /&gt;
&lt;a href=&quot;http://www.example.com/links.php&quot;&gt;Links&lt;/a&gt; -&lt;br /&gt;
&lt;a href=&quot;http://www.example.com/contact.php&quot;&gt;Contact Us&lt;/a&gt; &lt;br /&gt;
Save the above file as &quot;menu.php&quot;. Now create a new file, &quot;index.php&quot; in the same directory as &quot;menu.php&quot;. Here we will take advantage of the include function to add our common menu.&lt;br /&gt;
index.php Code:&lt;br /&gt;
&lt;!--?php include(&quot;menu.php&quot;); ?--&gt;&lt;br /&gt;
&lt;br /&gt;
This is my home page that uses a common menu to save me time when I add&lt;br /&gt;
new pages to my website!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Display:&lt;br /&gt;
Home - About Us - Links - Contact Us&lt;br /&gt;
This is my home page that uses a common menu to save me time when I add new pages to my website!&lt;br /&gt;
And we would do the same thing for &quot;about.php&quot;, &quot;links.php&quot;, and &quot;contact.php&quot;. Just think how terrible it would be if you had 15 or more pages with a common menu and you decided to add another web page to that site. You would have to go in an manually edit every single file to add this new page, but with include files you simply have to change &quot;menu.php&quot; and all your problems are solved. Avoid such troublesome occasions with a simple include file.&lt;br /&gt;
What do Visitors See?&lt;br /&gt;
If we were to use the include function to include a common menu on each of our web pages, what would the visitor see if they viewed the source of &quot;index.php&quot;? Well, because the include function is pretty much the same as copying and pasting, the visitors would see:&lt;br /&gt;
View Source of index.php to a Visitor:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.blogger.com/index.php&quot;&gt;Home&lt;/a&gt; -&lt;br /&gt;
&lt;a href=&quot;http://www.blogger.com/about.php&quot;&gt;About Us&lt;/a&gt; -&lt;br /&gt;
&lt;a href=&quot;http://www.blogger.com/links.php&quot;&gt;Links&lt;/a&gt; -&lt;br /&gt;
&lt;a href=&quot;http://www.blogger.com/contact.php&quot;&gt;Contact Us&lt;/a&gt; &lt;br /&gt;
&lt;br /&gt;
This is my home page that uses a common menu to save me time when I add&lt;br /&gt;
new pages to my website!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The visitor would actually see all the HTML code as one long line of HTML code, because we have not inserted any new line characters. We did some formatting above to make it easier to read. We will be discussing new line characters later.&lt;br /&gt;
&lt;b&gt;Include Recap&lt;/b&gt;&lt;br /&gt;
The include command simply takes all the text that exists in the specified file and copies it into the file that uses the include function. Include is quite useful when you want to include the same PHP, HTML, or text segment on multiple pages of a website. The include function is used widely by PHP web developers.&lt;br /&gt;
The next lesson will talk about a slight variation of the include function: the require function. It is often best to use the require function instead of the include function in your PHP Code. Read the next lesson to find out why!&lt;br /&gt;
&lt;b&gt;PHP Require Function&lt;/b&gt;&lt;br /&gt;
Just like the previous lesson, the require function is used to include a file into your PHP code. However there is one huge difference between the two functions, though it might not seem that big of a deal.&lt;br /&gt;
Require vs Include&lt;br /&gt;
When you include a file with the include function and PHP cannot find it you will see an error message like the following:&lt;br /&gt;
PHP Code:&lt;br /&gt;
&lt;!--?php&lt;/p--&gt;&lt;br /&gt;
include(&quot;noFileExistsHere.php&quot;);&lt;br /&gt;
echo &quot;Hello World!&quot;;&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
Display:&lt;br /&gt;
Warning: main(noFileExistsHere.php): failed to open stream: No such file or directory in /home/websiteName/FolderName/tizagScript.php on line 2 Warning: main(): Failed opening &#39;noFileExistsHere.php&#39; for inclusion (include_path=&#39;.:/usr/lib/php:/usr/local/lib/php&#39;) in /home/websiteName/FolderName/tizagScript.php on line 2 Hello World!&lt;br /&gt;
Notice that our echo statement is still executed, this is because a Warning does not prevent our PHP script from running. On the other hand, if we did the same example but used the require statement we would get something like the following example.&lt;br /&gt;
&lt;b&gt;PHP Code:&lt;/b&gt;&lt;br /&gt;
&lt;!--?php&lt;/p--&gt;&lt;br /&gt;
require(&quot;noFileExistsHere.php&quot;);&lt;br /&gt;
echo &quot;Hello World!&quot;;&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
Display:&lt;br /&gt;
Warning: main(noFileExistsHere.php): failed to open stream: No such file or directory in /home/websiteName/FolderName/tizagScript.php on line 2 Fatal error: main(): Failed opening required &#39;noFileExistsHere.php&#39; (include_path=&#39;.:/usr/lib/php:/usr/local/lib/php&#39;) in /home/websiteName/FolderName/tizagScript.php on line 2&lt;br /&gt;
The echo statement was not executed because our script execution died after the require function returned a fatal error! We recommend that you use require instead of include because your scripts should not be executing if necessary files are missing or misnamed.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://webdesigntipstrick.blogspot.com/feeds/5390397893914879448/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://webdesigntipstrick.blogspot.com/2012/07/php-include-function-with-example.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4358669149008391889/posts/default/5390397893914879448'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4358669149008391889/posts/default/5390397893914879448'/><link rel='alternate' type='text/html' href='http://webdesigntipstrick.blogspot.com/2012/07/php-include-function-with-example.html' title='PHP Include Function with example Tutorial'/><author><name>Admin</name><uri>http://www.blogger.com/profile/05350530015134205170</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4358669149008391889.post-833911514892112886</id><published>2012-07-11T23:54:00.002-07:00</published><updated>2012-07-11T23:54:49.600-07:00</updated><title type='text'>PHP Strings and Operators with example tutorial</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;b&gt;PHP - Strings&lt;/b&gt;&lt;br /&gt;
In the last lesson, PHP Echo, we used strings a bit, but didn&#39;t talk about them in depth. Throughout your PHP career you will be using strings a great deal, so it is important to have a basic understanding of PHP strings.&lt;br /&gt;
&lt;b&gt;PHP - String Creation&lt;/b&gt;&lt;br /&gt;
Before you can use a string you have to create it! A string can be used directly in a function or it can be stored in a variable. Below we create the exact same string twice: first storing it into a variable and in the second case we place the string directly into a function.&lt;br /&gt;
&lt;b&gt;PHP Code:&lt;/b&gt;&lt;br /&gt;
$my_string = &quot;Tizag - Unlock your potential!&quot;;&lt;br /&gt;
echo &quot;Tizag - Unlock your potential!&quot;;&lt;br /&gt;
echo $my_string;&lt;br /&gt;
In the above example the first string will be stored into the variable $my_string, while the second string will be used in the echo function and not be stored. Remember to save your strings into variables if you plan on using them more than once! Below is the output from our example code. They look identical just as we thought.&lt;br /&gt;
Display:&lt;br /&gt;
Tizag - Unlock your potential! Tizag - Unlock your potential!&lt;br /&gt;
&lt;b&gt;PHP - String Creation Single Quotes&lt;/b&gt;&lt;br /&gt;
Thus far we have created strings using double-quotes, but it is just as correct to create a string using single-quotes, otherwise known as apostrophes.&lt;br /&gt;
&lt;b&gt;PHP Code:&lt;/b&gt;&lt;br /&gt;
$my_string = &#39;Tizag - Unlock your potential!&#39;;&lt;br /&gt;
echo &#39;Tizag - Unlock your potential!&#39;;&lt;br /&gt;
echo $my_string;&lt;br /&gt;
If you want to use a single-quote within the string you have to escape the single-quote with a backslash \ . Like this: \&#39; !&lt;br /&gt;
&lt;b&gt;PHP Code:&lt;/b&gt;&lt;br /&gt;
echo &#39;Tizag - It\&#39;s Neat!&#39;;&lt;br /&gt;
&lt;b&gt;PHP - String Creation Double-Quotes&lt;/b&gt;&lt;br /&gt;
We have used double-quotes and will continue to use them as the primary method for forming strings. Double-quotes allow for many special escaped characters to be used that you cannot do with a single-quote string. Once again, a backslash is used to escape a character.&lt;br /&gt;
&lt;b&gt;PHP Code:&lt;/b&gt;&lt;br /&gt;
$newline = &quot;A newline is \n&quot;;&lt;br /&gt;
$return = &quot;A carriage return is \r&quot;;&lt;br /&gt;
$tab = &quot;A tab is \t&quot;;&lt;br /&gt;
$dollar = &quot;A dollar sign is \$&quot;;&lt;br /&gt;
$doublequote = &quot;A double-quote is \&quot;&quot;;&lt;br /&gt;
Note: If you try to escape a character that doesn&#39;t need to be, such as an apostrophe, then the backslash will show up when you output the string.&lt;br /&gt;
These escaped characters are not very useful for outputting to a web page because HTML ignore extra white space. A tab, newline, and carriage return are all examples of extra (ignorable) white space. However, when writing to a file that may be read by human eyes these escaped characters are a valuable tool!&lt;br /&gt;
&lt;b&gt;PHP - String Creation Heredoc&lt;/b&gt;&lt;br /&gt;
The two methods above are the traditional way to create strings in most programming languages. PHP introduces a more robust string creation tool called heredoc that lets the programmer create multi-line strings without using quotations. However, creating a string using heredoc is more difficult and can lead to problems if you do not properly code your string! Here&#39;s how to do it:&lt;br /&gt;
&lt;b&gt;PHP Code:&lt;/b&gt;&lt;br /&gt;
$my_string = &amp;lt;&amp;lt;&lt;test&lt; p=&quot;&quot;&gt;&lt;/test&lt;&gt;&lt;br /&gt;
Tizag.com&lt;br /&gt;
Webmaster Tutorials&lt;br /&gt;
Unlock your potential!&lt;br /&gt;
TEST;&lt;br /&gt;
echo $my_string;&lt;br /&gt;
There are a few very important things to remember when using heredoc.&lt;br /&gt;
• Use &amp;lt;&amp;lt;&amp;lt; and some identifier that you choose to begin the heredoc. In this example we chose TEST as our identifier.&lt;br /&gt;
• Repeat the identifier followed by a semicolon to end the heredoc string creation. In this example that was TEST;&lt;br /&gt;
• The closing sequence TEST; must occur on a line by itself and cannot be indented!&lt;br /&gt;
Another thing to note is that when you output this multi-line string to a web page, it will not span multiple lines because we did not have any &lt;br /&gt; tags contained inside our string! Here is the output made from the code above.&lt;br /&gt;
Display:&lt;br /&gt;
Tizag.com Webmaster Tutorials Unlock your potential!&lt;br /&gt;
Once again, take great care in following the heredoc creation guidelines to avoid any headaches.&lt;br /&gt;
&lt;b&gt;PHP - Operators&lt;/b&gt;&lt;br /&gt;
In all programming languages, operators are used to manipulate or perform operations on variables and values. You have already seen the string concatenation operator &quot;.&quot; in the Echo Lesson and the assignment operator &quot;=&quot; in pretty much every PHP example so far.&lt;br /&gt;
There are many operators used in PHP, so we have separated them into the following categories to make it easier to learn them all.&lt;br /&gt;
• Assignment Operators&lt;br /&gt;
• Arithmetic Operators&lt;br /&gt;
• Comparison Operators&lt;br /&gt;
• String Operators&lt;br /&gt;
• Combination Arithmetic &amp;amp; Assignment Operators&lt;br /&gt;
Assignment Operators&lt;br /&gt;
Assignment operators are used to set a variable equal to a value or set a variable to another variable&#39;s value. Such an assignment of value is done with the &quot;=&quot;, or equal character. Example:&lt;br /&gt;
• $my_var = 4;&lt;br /&gt;
• $another_var = $my_var&lt;br /&gt;
Now both $my_var and $another_var contain the value 4. Assignments can also be used in conjunction with arithmetic operators.&lt;br /&gt;
Arithmetic Operators&lt;br /&gt;
Operator&lt;br /&gt;
English&lt;br /&gt;
Example&lt;br /&gt;
+&lt;br /&gt;
Addition&lt;br /&gt;
2 + 4&lt;br /&gt;
-&lt;br /&gt;
Subtraction&lt;br /&gt;
6 - 2&lt;br /&gt;
*&lt;br /&gt;
Multiplication&lt;br /&gt;
5 * 3&lt;br /&gt;
/&lt;br /&gt;
Division&lt;br /&gt;
15 / 3&lt;br /&gt;
%&lt;br /&gt;
Modulus&lt;br /&gt;
43 % 10&lt;br /&gt;
PHP Code:&lt;br /&gt;
$addition = 2 + 4;&lt;br /&gt;
$subtraction = 6 - 2;&lt;br /&gt;
$multiplication = 5 * 3;&lt;br /&gt;
$division = 15 / 3;&lt;br /&gt;
$modulus = 5 % 2;&lt;br /&gt;
echo &quot;Perform addition: 2 + 4 = &quot;.$addition.&quot;&lt;br /&gt;&quot;;&lt;br /&gt;
echo &quot;Perform subtraction: 6 - 2 = &quot;.$subtraction.&quot;&lt;br /&gt;&quot;;&lt;br /&gt;
echo &quot;Perform multiplication: 5 * 3 = &quot;.$multiplication.&quot;&lt;br /&gt;&quot;;&lt;br /&gt;
echo &quot;Perform division: 15 / 3 = &quot;.$division.&quot;&lt;br /&gt;&quot;;&lt;br /&gt;
echo &quot;Perform modulus: 5 % 2 = &quot; . $modulus&lt;br /&gt;
. &quot;. Modulus is the remainder after the division operation has been performed.&lt;br /&gt;
In this case it was 5 / 2, which has a remainder of 1.&quot;;&lt;br /&gt;
Display:&lt;br /&gt;
Perform addition: 2 + 4 = 6 Perform subtraction: 6 - 2 = 4 Perform multiplication: 5 * 3 = 15 Perform division: 15 / 3 = 5 Perform modulus: 5 % 2 = 1. Modulus is the remainder after the division operation has been performed. In this case it was 5 / 2, which has a remainder of 1.&lt;br /&gt;
Comparison Operators&lt;br /&gt;
Comparisons are used to check the relationship between variables and/or values. If you would like to see a simple example of a comparison operator in action, check out our If Statement Lesson. Comparison operators are used inside conditional statements and evaluate to either true or false. Here are the most important comparison operators of PHP. Assume: $x = 4 and $y = 5;&lt;br /&gt;
Operator&lt;br /&gt;
English&lt;br /&gt;
Example&lt;br /&gt;
Result&lt;br /&gt;
==&lt;br /&gt;
Equal To&lt;br /&gt;
$x == $y&lt;br /&gt;
false&lt;br /&gt;
!=&lt;br /&gt;
Not Equal To&lt;br /&gt;
$x != $y&lt;br /&gt;
true&lt;br /&gt;
&amp;lt;&lt;br /&gt;
Less Than&lt;br /&gt;
$x &amp;lt; $y&lt;br /&gt;
true&lt;br /&gt;
&amp;gt;&lt;br /&gt;
Greater Than&lt;br /&gt;
$x &amp;gt; $y&lt;br /&gt;
false&lt;br /&gt;
&amp;lt;=&lt;br /&gt;
Less Than or Equal To&lt;br /&gt;
$x &amp;lt;= $y&lt;br /&gt;
true&lt;br /&gt;
&amp;gt;=&lt;br /&gt;
Greater Than or Equal To&lt;br /&gt;
$x &amp;gt;= $y&lt;br /&gt;
false&lt;br /&gt;
String Operators&lt;br /&gt;
As we have already seen in the Echo Lesson, the period &quot;.&quot; is used to add two strings together, or more technically, the period is the concatenation operator for strings.&lt;br /&gt;
PHP Code:&lt;br /&gt;
$a_string = &quot;Hello&quot;;&lt;br /&gt;
$another_string = &quot; Billy&quot;;&lt;br /&gt;
$new_string = $a_string . $another_string;&lt;br /&gt;
echo $new_string . &quot;!&quot;;&lt;br /&gt;
Display:&lt;br /&gt;
Hello Billy!&lt;br /&gt;
Combination Arithmetic &amp;amp; Assignment Operators&lt;br /&gt;
In programming it is a very common task to have to increment a variable by some fixed amount. The most common example of this is a counter. Say you want to increment a counter by 1, you would have:&lt;br /&gt;
• $counter = $counter + 1;&lt;br /&gt;
However, there is a shorthand for doing this.&lt;br /&gt;
• $counter += 1;&lt;br /&gt;
This combination assignment/arithmetic operator would accomplish the same task. The downside to this combination operator is that it reduces code readability to those programmers who are not used to such an operator. Here are some examples of other common shorthand operators. In general, &quot;+=&quot; and &quot;-=&quot; are the most widely used combination operators.&lt;br /&gt;
Operator&lt;br /&gt;
English&lt;br /&gt;
Example&lt;br /&gt;
Equivalent Operation&lt;br /&gt;
+=&lt;br /&gt;
Plus Equals&lt;br /&gt;
$x += 2;&lt;br /&gt;
$x = $x + 2;&lt;br /&gt;
-=&lt;br /&gt;
Minus Equals&lt;br /&gt;
$x -= 4;&lt;br /&gt;
$x = $x - 4;&lt;br /&gt;
*=&lt;br /&gt;
Multiply Equals&lt;br /&gt;
$x *= 3;&lt;br /&gt;
$x = $x * 3;&lt;br /&gt;
/=&lt;br /&gt;
Divide Equals&lt;br /&gt;
$x /= 2;&lt;br /&gt;
$x = $x / 2;&lt;br /&gt;
%=&lt;br /&gt;
Modulo Equals&lt;br /&gt;
$x %= 5;&lt;br /&gt;
$x = $x % 5;&lt;br /&gt;
.=&lt;br /&gt;
Concatenate Equals&lt;br /&gt;
$my_str.=&quot;hello&quot;;&lt;br /&gt;
$my_str = $my_str . &quot;hello&quot;;&lt;br /&gt;
Pre/Post-Increment &amp;amp; Pre/Post-Decrement&lt;br /&gt;
This may seem a bit absurd, but there is even a shorter shorthand for the common task of adding 1 or subtracting 1 from a variable. To add one to a variable or &quot;increment&quot; use the &quot;++&quot; operator:&lt;br /&gt;
• $x++; Which is equivalent to $x += 1; or $x = $x + 1;&lt;br /&gt;
To subtract 1 from a variable, or &quot;decrement&quot; use the &quot;--&quot; operator:&lt;br /&gt;
• $x--; Which is equivalent to $x -= 1; or $x = $x - 1;&lt;br /&gt;
In addition to this &quot;shorterhand&quot; technique, you can specify whether you want the increment to before the line of code is being executed or after the line has executed. Our PHP code below will display the difference.&lt;br /&gt;
PHP Code:&lt;br /&gt;
$x = 4;&lt;br /&gt;
echo &quot;The value of x with post-plusplus = &quot; . $x++;&lt;br /&gt;
echo &quot;&lt;br /&gt; The value of x after the post-plusplus is &quot; . $x;&lt;br /&gt;
$x = 4;&lt;br /&gt;
echo &quot;&lt;br /&gt;The value of x with with pre-plusplus = &quot; . ++$x;&lt;br /&gt;
echo &quot;&lt;br /&gt; The value of x after the pre-plusplus is &quot; . $x;&lt;br /&gt;
Display:&lt;br /&gt;
The value of x with post-plusplus = 4 The value of x after the post-plusplus is = 5 The value of x with with pre-plusplus = 5 The value of x after the pre-plusplus is = 5&lt;br /&gt;
As you can see the value of $x++ is not reflected in the echoed text because the variable is not incremented until after the line of code is executed. However, with the pre-increment &quot;++$x&quot; the variable does reflect the addition immediately.&lt;br /&gt;
Using Comments in PHP&lt;br /&gt;
Comments in PHP are similar to comments that are used in HTML. The PHP comment syntax always begins with a special character sequence and all text that appears between the start of the comment and the end will be ignored by the browser.&lt;br /&gt;
In HTML a comment&#39;s main purpose is to serve as a note to you, the web developer or to others who may view your website&#39;s source code. However, PHP&#39;s comments are different in that they will not be displayed to your visitors. The only way to view PHP comments is to open the PHP file for editing. This makes PHP comments only useful to PHP programmers.&lt;br /&gt;
In case you forgot what an HTML comment looked like, see our example below.&lt;br /&gt;
HTML Code:&lt;br /&gt;
&lt;!--- This is an HTML Comment --&gt;&lt;br /&gt;
PHP Comment Syntax: Single Line Comment&lt;br /&gt;
While there is only one type of comment in HTML, PHP has two types. The first type we will discuss is the single line comment. The single line comment tells the interpreter to ignore everything that occurs on that line to the right of the comment. To do a single line comment type &quot;//&quot; and all text to the right will be ignored by PHP interpreter.&lt;br /&gt;
PHP Code:&lt;br /&gt;
&lt;!--?php&lt;/p--&gt;&lt;br /&gt;
echo &quot;Hello World!&quot;; // This will print out Hello World!&lt;br /&gt;
echo &quot;&lt;br /&gt;Psst...You can&#39;t see my PHP comments!&quot;; // echo &quot;nothing&quot;;&lt;br /&gt;
// echo &quot;My name is Humperdinkle!&quot;;&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
Display:&lt;br /&gt;
Hello World! Psst...You can&#39;t see my PHP comments!&lt;br /&gt;
Notice that a couple of our echo statements were not evaluated because we commented them out with the single line comment. This type of line commenting is often used for quick notes about complex and confusing code or to temporarily remove a line of PHP code.&lt;br /&gt;
PHP Comment Syntax: Multiple Line Comment&lt;br /&gt;
Similiar to the HTML comment, the multi-line PHP comment can be used to comment out large blocks of code or writing multiple line comments. The multiple line PHP comment begins with &quot; /* &quot; and ends with &quot; */ &quot;.&lt;br /&gt;
PHP Code:&lt;br /&gt;
&lt;!--?php&lt;/p--&gt;&lt;br /&gt;
/* This Echo statement will print out my message to the&lt;br /&gt;
the place in which I reside on. In other words, the World. */&lt;br /&gt;
echo &quot;Hello World!&quot;;&lt;br /&gt;
/* echo &quot;My name is Humperdinkle!&quot;;&lt;br /&gt;
echo &quot;No way! My name is Uber PHP Programmer!&quot;;&lt;br /&gt;
*/&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
Display:&lt;br /&gt;
Hello World!&lt;br /&gt;
Good Commenting Practices&lt;br /&gt;
One of the best commenting practices that I can recommend to new PHP programmers is....USE THEM!! So many people write complex PHP code and are either too lazy to write good comments or believe the commenting is not needed. However, do you really believe that you will remember exactly what you were thinking when looking at this code a year or more down the road?&lt;br /&gt;
Let the comments permeate your code and you will be a happier PHPer in the future. Use single line comments for quick notes about a tricky part in your code and use multiple line comments when you need to describe something in greater depth than a simple note.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://webdesigntipstrick.blogspot.com/feeds/833911514892112886/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://webdesigntipstrick.blogspot.com/2012/07/php-strings-and-operators-with-example.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4358669149008391889/posts/default/833911514892112886'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4358669149008391889/posts/default/833911514892112886'/><link rel='alternate' type='text/html' href='http://webdesigntipstrick.blogspot.com/2012/07/php-strings-and-operators-with-example.html' title='PHP Strings and Operators with example tutorial'/><author><name>Admin</name><uri>http://www.blogger.com/profile/05350530015134205170</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4358669149008391889.post-8654157446819861632</id><published>2012-07-11T23:51:00.007-07:00</published><updated>2012-07-11T23:51:54.210-07:00</updated><title type='text'>PHP - Variables with Example tutorial</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;b&gt;PHP - Variables&lt;/b&gt;&lt;br /&gt;
If you have never had any programming, Algebra, or scripting experience, then the concept of variables might be a new concept to you. A detailed explanation of variables is beyond the scope of this tutorial, but we&#39;ve included a refresher crash course to guide you.&lt;br /&gt;
A variable is a means of storing a value, such as text string &quot;Hello World!&quot; or the integer value 4. A variable can then be reused throughout your code, instead of having to type out the actual value over and over again. In PHP you define a variable with the following form:&lt;br /&gt;
• $variable_name = Value;&lt;br /&gt;
If you forget that dollar sign at the beginning, it will not work. This is a common mistake for new PHP programmers!&lt;br /&gt;
A Quick Variable Example&lt;br /&gt;
Say that we wanted to store the values that we talked about in the above paragraph. How would we go about doing this? We would first want to make a variable name and then set that equal to the value we want. See our example below for the correct way to do this.&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;PHP Code:&lt;/b&gt;&lt;br /&gt;
&lt;!--?php&lt;/p--&gt;&lt;br /&gt;
$hello = &quot;Hello World!&quot;;&lt;br /&gt;
$a_number = 4;&lt;br /&gt;
$anotherNumber = 8;&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
Note for programmers: PHP does not require variables to be declared before being initialized.&lt;br /&gt;
PHP Variable Naming Conventions&lt;br /&gt;
There are a few rules that you need to follow when choosing a name for your PHP variables.&lt;br /&gt;
• PHP variables must start with a letter or underscore &quot;_&quot;.&lt;br /&gt;
• PHP variables may only be comprised of alpha-numeric characters and underscores. a-z, A-Z, 0-9, or _ .&lt;br /&gt;
• Variables with more than one word should be separated with underscores. $my_variable&lt;br /&gt;
• Variables with more than one word can also be distinguished with capitalization. $myVariable&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;PHP - Echo&lt;/b&gt;&lt;br /&gt;
As you saw in the previous lesson, the PHP function echo is a means of outputting text to the web browser. Throughout your PHP career you will be using the echo function more than any other. So let&#39;s give it a solid perusal!&lt;br /&gt;
Outputting a String&lt;br /&gt;
To output a string, like we have done in previous lessons, use the PHP echo function. You can place either a string variable or you can use quotes, like we do below, to create a string that the echo function will output.&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;PHP Code:&lt;/b&gt;&lt;br /&gt;
&lt;!--?php&lt;/p--&gt;&lt;br /&gt;
$myString = &quot;Hello!&quot;;&lt;br /&gt;
echo $myString;&lt;br /&gt;
echo &quot;&lt;br /&gt;
&lt;h5&gt;
I love using PHP!&lt;/h5&gt;
&quot;;&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
Display:&lt;br /&gt;
Hello!&lt;br /&gt;
I love using PHP!&lt;br /&gt;
In the above example we output &quot;Hello!&quot; without a hitch. The text we are outputting is being sent to the user in the form of a web page, so it is important that we use proper HTML syntax!&lt;br /&gt;
In our second echo statement we use echo to write a valid Header 5 HTML statement. To do this we simply put the &lt;br /&gt;
&lt;h5&gt;
 at the beginning of the string and closed it at the end of the string. Just because you&#39;re using PHP to make web pages does not mean you can forget about HTML syntax!&lt;br /&gt;
Careful When Echoing Quotes!&lt;br /&gt;
It is pretty cool that you can output HTML with PHP. However, you must be careful when using HTML code or any other string that includes quotes! The echo function uses quotes to define the beginning and end of the string, so you must use one of the following tactics if your string contains quotations:&lt;br /&gt;
• Don&#39;t use quotes inside your string&lt;br /&gt;
• Escape your quotes that are within the string with a slash. To escape a quote just place a slash directly before the quotation mark, i.e. \&quot;&lt;br /&gt;
• Use single quotes (apostrophes) for quotes inside your string.&lt;br /&gt;
See our example below for the right and wrong use of the echo function:&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;PHP Code:&lt;/b&gt;&lt;br /&gt;
&lt;!--?php&lt;/p--&gt;&lt;br /&gt;
// This won&#39;t work because of the quotes around specialH5!&lt;br /&gt;
echo &quot;&lt;/h5&gt;
&lt;h5 class=&quot;specialH5&quot;&gt;
I love using PHP!&lt;/h5&gt;
&quot;;&lt;br /&gt;
// OK because we escaped the quotes!&lt;br /&gt;
echo &quot;&lt;br /&gt;
&lt;h5 class=&quot;\&amp;quot;specialH5\&amp;quot;&quot;&gt;
I love using PHP!&lt;/h5&gt;
&quot;;&lt;br /&gt;
// OK because we used an apostrophe &#39;&lt;br /&gt;
echo &quot;&lt;br /&gt;
&lt;h5 class=&quot;specialH5&quot;&gt;
I love using PHP!&lt;/h5&gt;
&quot;;&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
If you want to output a string that includes quotations, either use an apostrophe ( &#39; ) or escape the quotations by placing a slash in front of it ( \&quot; ). The slash will tell PHP that you want the quotation to be used within the string and NOT to be used to end echo&#39;s string.&lt;br /&gt;
Echoing Variables&lt;br /&gt;
Echoing variables is very easy. The PHP developers put in some extra work to make the common task of echoing all variables nearly foolproof! No quotations are required, even if the variable does not hold a string. Below is the correct format for echoing a variable.&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;PHP Code:&lt;/b&gt;&lt;br /&gt;
&lt;!--?php&lt;/p--&gt;&lt;br /&gt;
$my_string = &quot;Hello Bob. My name is: &quot;;&lt;br /&gt;
$my_number = 4;&lt;br /&gt;
$my_letter = a;&lt;br /&gt;
echo $my_string;&lt;br /&gt;
echo $my_number;&lt;br /&gt;
echo $my_letter;&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
Display:&lt;br /&gt;
Hello Bob. My name is: 4a&lt;br /&gt;
Echoing Variables and Text Strings&lt;br /&gt;
You can also combine text strings and variables. By doing such a conjunction you save yourself from having to do a large number of echo statements. Variables and text strings are joined together with a period( . ). The example below shows how to do such a combination.&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;PHP Code:&lt;/b&gt;&lt;br /&gt;
&lt;!--?php&lt;/p--&gt;&lt;br /&gt;
$my_string = &quot;Hello Bob. My name is: &quot;;&lt;br /&gt;
$newline = &quot;&lt;br /&gt;&quot;;&lt;br /&gt;
echo $my_string.&quot;Bobettta&quot;.$newline;&lt;br /&gt;
echo &quot;Hi, I&#39;m Bob. Who are you? &quot;.$my_string.$newline;&lt;br /&gt;
echo &quot;Hi, I&#39;m Bob. Who are you? &quot;.$my_string.&quot;Bobetta&quot;;&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
Display:&lt;br /&gt;
Hello Bob. My name is: Bobetta Hi, I&#39;m Bob. Who are you? Hello Bob. My name is: Hi, I&#39;m Bob. Who are you? Hello Bob. My name is: Bobetta&lt;br /&gt;
This combination can be done multiple times, as the example shows. This method of joining two or more strings together is called concatenation and we will talk more about this and other forms of string manipulation in our string lesson.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://webdesigntipstrick.blogspot.com/feeds/8654157446819861632/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://webdesigntipstrick.blogspot.com/2012/07/php-variables-with-example-tutorial.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4358669149008391889/posts/default/8654157446819861632'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4358669149008391889/posts/default/8654157446819861632'/><link rel='alternate' type='text/html' href='http://webdesigntipstrick.blogspot.com/2012/07/php-variables-with-example-tutorial.html' title='PHP - Variables with Example tutorial'/><author><name>Admin</name><uri>http://www.blogger.com/profile/05350530015134205170</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4358669149008391889.post-4704116994852294882</id><published>2012-07-11T23:49:00.003-07:00</published><updated>2012-07-11T23:49:40.959-07:00</updated><title type='text'>Php Syntax with Example Tutorial</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;b&gt;PHP - Syntax&lt;/b&gt;&lt;br /&gt;
Before we talk about PHP&#39;s syntax, let us first define what syntax is referring to.&lt;br /&gt;
• Syntax - The rules that must be followed to write properly structured code.&lt;br /&gt;
PHP&#39;s syntax and semantics are similar to most other programming languages (C, Java, Perl) with the addition that all PHP code is contained with a tag, of sorts. All PHP code must be contained within the following...&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;PHP Code:&lt;/b&gt;&lt;br /&gt;
&lt;!--?php&lt;/p--&gt;&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
or the shorthand PHP tag that requires shorthand support to be enabled&lt;br /&gt;
on your server...&lt;br /&gt;
&lt;!--?&lt;/p--&gt;&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
If you are writing PHP scripts and plan on distributing them, we suggest that you use the standard form (which includes the ?php) rather than the shorthand form. This will ensure that your scripts will work, even when running on other servers with different settings.&lt;br /&gt;
&lt;br /&gt;
How to Save Your PHP Pages&lt;br /&gt;
If you have PHP inserted into your HTML and want the web browser to interpret it correctly, then you must save the file with a .php extension, instead of the standard .html extension. So be sure to check that you are saving your files correctly. Instead of index.html, it should be index.php if there is PHP code in the file.&lt;br /&gt;
Example Simple HTML &amp;amp; PHP Page&lt;br /&gt;
Below is an example of one of the easiest PHP and HTML page that you can create and still follow web standards.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;PHP and HTML Code:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;title&gt;My First PHP Page&lt;/title&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;!--?php&lt;/p--&gt;&lt;br /&gt;
echo &quot;Hello World!&quot;;&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Display:&lt;br /&gt;
Hello World!&lt;br /&gt;
&lt;br /&gt;
If you save this file and place it on PHP enabled server and load it up in your web browser, then you should see &quot;Hello World!&quot; displayed. If not, please check that you followed our example correctly.&lt;br /&gt;
We used the PHP function echo to write &quot;Hello World!&quot; and we will be talking in greater depth about this PHP function and many others later on in this tutorial.&lt;br /&gt;
The Semicolon!&lt;br /&gt;
As you may or may not have noticed in the above example, there was a semicolon after the line of PHP code. The semicolon signifies the end of a PHP statement and should never be forgotten. For example, if we repeated our &quot;Hello World!&quot; code several times, then we would need to place a semicolon at the end of each statement.&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;PHP and HTML Code:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;title&gt;My First PHP Page&lt;/title&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;!--?php&lt;/p--&gt;&lt;br /&gt;
echo &quot;Hello World! &quot;;&lt;br /&gt;
echo &quot;Hello World! &quot;;&lt;br /&gt;
echo &quot;Hello World! &quot;;&lt;br /&gt;
echo &quot;Hello World! &quot;;&lt;br /&gt;
echo &quot;Hello World! &quot;;&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Display:&lt;br /&gt;
Hello World! Hello World! Hello World! Hello World! Hello World!&lt;br /&gt;
White Space&lt;br /&gt;
As with HTML, whitespace is ignored between PHP statements. This means it is OK to have one line of PHP code, then 20 lines of blank space before the next line of PHP code. You can also press tab to indent your code and the PHP interpreter will ignore those spaces as well.&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;PHP and HTML Code:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;title&gt;My First PHP Page&lt;/title&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;!--?php&lt;/p--&gt;&lt;br /&gt;
echo &quot;Hello World!&quot;;&lt;br /&gt;
echo &quot;Hello World!&quot;;&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Display:&lt;br /&gt;
Hello World!Hello World!&lt;br /&gt;
This is perfectly legal PHP code.&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://webdesigntipstrick.blogspot.com/feeds/4704116994852294882/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://webdesigntipstrick.blogspot.com/2012/07/php-syntax-with-example-tutorial.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4358669149008391889/posts/default/4704116994852294882'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4358669149008391889/posts/default/4704116994852294882'/><link rel='alternate' type='text/html' href='http://webdesigntipstrick.blogspot.com/2012/07/php-syntax-with-example-tutorial.html' title='Php Syntax with Example Tutorial'/><author><name>Admin</name><uri>http://www.blogger.com/profile/05350530015134205170</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4358669149008391889.post-8421674941488773610</id><published>2012-07-11T23:31:00.002-07:00</published><updated>2012-07-11T23:33:20.421-07:00</updated><title type='text'>PHP Installation</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;Windows&amp;nbsp;Installation&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
1. Download the software at: www.apachefriends.org/en/xampp-windows.html#641&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Select the Installer option under the “Basic Package.” At the time of this writing, a direct link to&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
version 1.5 for Windows was: http://prdownloads.sourceforge.net/xampp/xampp-win32-1.5.0-pl1-&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
installer.exe&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
You may be taken to a page that gives you a bunch of different places to download from. Just click&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
one of the download buttons. Once downloaded, the installer works like most Windows installers.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
2. Double click the .exe file you downloaded.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
A window opens asking you to select the language you’d like to use.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
3. Choose a language from the menu and click the OK button&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
A Setup Wizard window appears, ready to step you through the set up process.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
4. Click the Next button, then click the Install button.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The various files needed are loaded onto your computer.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
5. Click the finish button, then when a window appears saying “Install XAMPP servers as service”&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
appears make a selection.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
A service starts up ever time you turn on your computer. In other words, do you want the Web server&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
and database server to startup whenever you turn on your PC? If you plan on doing a lot of&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
development, day-in and day-out, you might want to choose “Yes.” Otherwise you’ll find that you’re&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
starting up the XAMPP control panel (see below) and turning on the servers every time you boot up.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
However, if you won’t be building database sites frequently, or you don’t have a lot of RAM in your&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
computer, you might want to choose “No.” This way you can manually turn on the servers (see “The&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
XAMPP Control Panel” below) when you need to work on a dynamic site.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
If you select “Yes” you will be taken through the same question for the Apache Web Server, the&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
MySQL database server and the FileZilla FTP server. It’s best to click “No” for the FileZilla FTP&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
server. You won’t need it for this tutorial, and since this is just a testing server, you won’t need to have&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
the ability to FTP to the computer—after all, all your files are already on your computer.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
6. Finally, launch a Web browser and type http://localhost/ in the location bar.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
You’ll encounter a page that lists a bunch of languages; click the language you prefer and you’ll be&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
taken to a kind of control panel for XAMPP on your computer (see Figure PHP Tutorial 1-1.)&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZzVAzFg4Te6sNE_DcawnQg9jF25DADsOhb-yHSQ8SE_LOfeelZ5mTNES9c_oNescKQSRqPkguPEzZcYtELOzYWObTBxURPUn3JQZfcBI2VvBuumItlx8QAEk-030wnZxFsnWLVMs0OYc/s1600/php1.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;367&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZzVAzFg4Te6sNE_DcawnQg9jF25DADsOhb-yHSQ8SE_LOfeelZ5mTNES9c_oNescKQSRqPkguPEzZcYtELOzYWObTBxURPUn3JQZfcBI2VvBuumItlx8QAEk-030wnZxFsnWLVMs0OYc/s400/php1.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;PHP Tutorial 1-1. Once installed, you can view your XAMPP page from&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; http://localhost/xampp/&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Once you’ve installed XAMPP, there will be a shortcut called XAMPP Control Panel on your desktop.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Double-click this to control the servers—you can turn the servers off and on, as well as turn them into&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
services which launch each time you start up your computer.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
To uninstall XAMPP, just go to C:\Program Files\ and delete the folder named XAMPP. That’s it!&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
For more information on XAMPP, included detailed installation and setup instructions visit&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
www.apachefriends.org/en/xampp-windows.html.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
I’m Comfortable Downloading and Installing Complex&amp;nbsp;&lt;span style=&quot;background-color: white;&quot;&gt;Software&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Windows&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
• Apache Web Server: Visit the Apache Web site and download and install version 2 of the Apache&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Web server: http://httpd.apache.org/download.cgi&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
• PHP: Go to the PHP site and download the PHP 5.05 Zip Package listed under “Windows Binaries”&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
at: www.php.net/downloads.php&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
• MySQL: Visit the MySQL download page at http://dev.mysql.com/downloads/mysql/4.0.html and&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
click the Windows (x86) link to download the installer.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
• PHPMyAdmin: For managing your MySQL database, you’ll use this free, Web-based tool. Download&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
the latest version at www.phpmyadmin.net/home_page/downloads.php. You can download a ZIP file&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
containing all of the files. These are just PHP pages and they’ll go inside your Web documents folder.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
It’s usually a good idea to create a folder in the Web site root folder with a name like pma (for&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
phpMyAdmin) and put all of the PHPMyAdmin files in there.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Dude, I Already Have PHP and MySQL Up and Running&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
OK. You’re all set, but you should make sure you either have PHPMyAdmin installed&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
(www.phpmyadmin.net/home_page/downloads.php) or you know how to load an SQL file into MySQL&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
from the command line. You’ll be doing that in the next phase of this setup.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Setting Up the Database and Web Site&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
To learn Dreamweaver’s dynamic features, you’ll be building a small Web application for the National&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Exasperator. In fact, you’ll turn the site’s online store into dynamic Web pages that will retrieve&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
information from a database and merge it with already-created HTML code.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
You’ll need the tutorial files to follow along. You can download them at www.sawmac.com/dw8/php.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Once you’ve downloaded and unzipped the files you’ll have a folder named DW_php, containing a folder&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
called nationalEx (the root folder for this Web site) and a file called nationalEx.sql (a SQL file that will let&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
you add the product data to your MySQL database).&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Putting the Web Pages in Place&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
To begin, move the nationalEx folder into the Web server’s root folder. If you followed the directions&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
above and installed the XAMPP versions of Apache, PHP and MySQL, the root folder should be located at&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
C:\XAMPP\htdocs on Windows, and Applications/XAMPP/htdocs on Mac. (If your Windows computer’s&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
main drive is not the C:\ drive, the root folder might be located on another drive—D:\, for instance.) Place&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
nationalEx inside the htdocs folder.&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Loading the Database&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The data for the National Exasperator store needs to be installed in your new MySQL server. There’s&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
actually a few steps you’ll need to complete. First you’ll create a new database (you’ll be loading the data&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
for the store into this); next, you’ll load the data into this new database; finally, you’ll create a new user for&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
the database (this will be a special account that you’ll use for accessing and updating the database.)&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Create the Database&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
1. In a Web browser type http://localhost/&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
If you used the XAMPP program as described above, this will take you to the main XAMPP page on&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
the new server. You’ll use a program called phpMyAdmin to administer the MySQL server.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
2. Click the phpMyAdmin link listed under “Tools” to go to the phpMyAdmin main page.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Note: If you set up the Web server, PHP and MySQL on your own, you’ll need to use&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
your Web browser to go to the PHPMyAdmin folder on your server. This might be&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
http://localhost/pma or http://localhost/phpmyadmin/ depending on your set up.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
3. In the Create New Database box type nationalEx and press the Create button (see Figure PHP Tutorial&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
1-3.)&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This creates a new database on the MySQL server. Next you’ll load a SQL file which will create the&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
required tables and add the needed data to the database (see Chapter 20 for more on SQL, databases&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
and tables.)&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqlgznaDYGPdWiaA0KhuHIMRJFJDeKRbmE5PU6-EPyV5EEs3wCdf5obgudjGfNa5DqYoZ0uYTdZiGAjZtFjw3brVMS9CwW6qzF3o98Izk2V7xar18Vsa_KoC9Jed3BNmTlQ4z9tynAEMA/s1600/php2.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;294&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqlgznaDYGPdWiaA0KhuHIMRJFJDeKRbmE5PU6-EPyV5EEs3wCdf5obgudjGfNa5DqYoZ0uYTdZiGAjZtFjw3brVMS9CwW6qzF3o98Izk2V7xar18Vsa_KoC9Jed3BNmTlQ4z9tynAEMA/s320/php2.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;The phpMyAdmin main page. Here you can create a new&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;database, select an already created database to work with and handle many&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;administrative tasks for MySQL.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: white;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
4. Click the SQL tab near the top of the page.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This takes you to a page that lets you type in a SQL query (see page xx of printed book), or load a text&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
file that has SQL commands in it. You’ll do the latter—load a text file that contains all of the SQL&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
necessary to create the tables and data for the database.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
5. Click the Browse button (see Figure PHP Tutorial 1-4. In the File Upload window that appears,&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
navigate to and select the file nationalEx.sql in the DW_PHP folder you downloaded earlier.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgD8QeYH1l8Q-AUgLraru5LKeONZ8wfdF8HCNhx7168khCDe7WhatBVPOcn2O4V7ZVmfzHzmbnE4u3Itwbe3QkVUZ4tNqaoJNNCLSo2O13guDb3XQot9lR4ZkkIIhK9nWMOzQqK0u2eBeg/s1600/php3.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;367&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgD8QeYH1l8Q-AUgLraru5LKeONZ8wfdF8HCNhx7168khCDe7WhatBVPOcn2O4V7ZVmfzHzmbnE4u3Itwbe3QkVUZ4tNqaoJNNCLSo2O13guDb3XQot9lR4ZkkIIhK9nWMOzQqK0u2eBeg/s400/php3.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; phpMyAdmin lets you load a SQL file, and execute the SQL&lt;span style=&quot;background-color: white;&quot;&gt;code inside the file. This is a great way &amp;nbsp; &amp;nbsp;to replicate data from another database. In fact&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;phpMyAdmin can help you export all of the tables and data from any database it has&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;background-color: white;&quot;&gt;access to.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
6. Click the Go button.&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The SQL in the file is executed: four new tables are created and a bunch of data is added. The last step&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
in prepping the database is to create a new MySQL user that has access to add to and update the&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
National Exasperator database.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
7. Click the link at the top of the page labeled Server: Localhost.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This returns you to the main phpMyAdmin page&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
8. Click the Privileges link in the middle column of links.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
9. Click the “Add a new user” link.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_SaA_t9DBKRMCi6z5bBFOFYY8nDGUgZn3VHCUDdkfDDua7IBssd2wrECAhsr-vDuBow_R-YY-Me9GoQi5YbPzxOyl-wc6m0F4xmmI6ZxhRA98EWaOO5Rz3AIpp1Xg7FfdsXMYJqaIZKY/s1600/php5.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;368&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_SaA_t9DBKRMCi6z5bBFOFYY8nDGUgZn3VHCUDdkfDDua7IBssd2wrECAhsr-vDuBow_R-YY-Me9GoQi5YbPzxOyl-wc6m0F4xmmI6ZxhRA98EWaOO5Rz3AIpp1Xg7FfdsXMYJqaIZKY/s400/php5.jpg&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Create a new user to access a database.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
10. Type nationalEx for the username and localhost for the Host. In the password field type nationalEx,&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
and in the re-type box type nationalEx again. The screen should look like Figure PHP Tutorial 1-6.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This will create a user whose name is nationalEx, whose password is nationalEx, and who can only&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
access them database locally from the server. This means someone out on the internet can’t try to login&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
to the MySQL server using the nationalEx account; only local access—for example, PHP pages being&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
run on the same computer—is allowed.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
In general, it is a very bad idea to make a password the same as a username, since it doesn’t take much&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
imagination for a hacker to figure this out and suddenly be in control of your database. But for this&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
example application, it’s best to keep things as simple as possible, so we can get to the more interesting&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
stuff (actually using Dreamweaver, for instance!)&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
11. Click the Go button at the bottom of the page.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The new user, nationalEx, is created and you’re taken to another Web page. Now you need to give that&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
user access to the National Exasperator database.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
12. Scroll down the page to the “Database-specific privileges” section; select nationalEx from the database&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
menu&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Setting Up Dreamweaver&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The first step in working on this dynamic Web application is to define a new site. The process of defining a&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
dynamic site, as outlined below, is slightly different than for static sites, but not any harder:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
1. Choose Site→New Sites.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The Site Definition window opens. Use Dreamweaver’s Site Wizard to help you set up this new site.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
2. If it isn’t already selected, click the Basic tab at the top of the window.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The first step is to give this new site a name.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
3. Type Exasperator Store in the first box and http://www.nationalExasperator.com/ in the second box.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
You’ve just told Dreamweaver the name you want to use while working on this site, and the URL of&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
the Web site. In a real world scenario, you’d type the address of your Web site.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
4. Click Next.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The next screen lets you choose whether you’re building a static or dynamic Web site.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
5. Select “Yes, I want to use a server technology” and choose PHP/MySQL from the pop-up menu. Click&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Next to proceed.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
In the next step, you’ll tell Dreamweaver where your local files are and where you intend to put the&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
files for the testing server.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
6. Select “Edit and test locally”.&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Dreamweaver provides three ways to work with dynamic Web page files and a testing server.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
“Edit and test locally” is a good choice when you’ve set up a Web and application server on your&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
computer (as you’ve done in this tutorial). Essentially, this means that you’re working on a Web site&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
located on a functioning Web server. In this way, you’ll preview the pages running on a real Web&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
server, so you can immediately test out all the nifty dynamic stuff.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The other two options are used when the testing server is located on another computer. This may be a&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
computer on your local network, or a full-fledged Web server running on the Internet that you connect&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
to using FTP.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
“Edit locally, then upload to remote testing server” is a good option when you can’t run a testing server&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
on your computer—for example you don’t have administrative privileges so you can’t install a Web&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
server, but you do have a Web hosting account that provides PHP and MySQL.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The last option should be used when the testing server is on another computer, but you’re the only&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
developer working on the files. Since the files are available on your local network, anyone in your&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
company or office who has access to the computer with the testing server can also edit those files.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Your Web pages can end up in an unrecoverable mess if you and someone else are simultaneously&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
editing and saving the exact same file.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The next step involves telling Dreamweaver where to find the files for the Web site.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
7. Click the folder at the right side of the middle of the window; navigate to and select the nationalEx&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
folder on the Web server. Click Next.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
If you used the XAMPP installation recommended in the set up instructions this will be C:\Program&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Files\xampp\htdocs\nationalEx\ (on Windows) or Applications:XAMPP:htdocs:nationalEx (on Mac).&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
You’ve nearly completed the setup.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
8. Type the URL of the test server in the box and click Test.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Dreamweaver may have already filled in this box. If the test server is running on your computer, the&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
URL begins with http://localhost/ and ends with the folder that contains the Web pages. In this case,&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
the URL is probably http://localhost/nationalEx/.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
If you get an error message when you click Test, you’ve probably entered the wrong URL.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
9. Click Next.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
You may get a warning box squawking about how the URL doesn’t match the testing server. This just&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
means that in step 3 above you didn’t specify any folder, but in step 7 you said the site was in a folder&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
named nationalEx. This means site-root relative links (see Chapter 5) won’t work. In a real world case,&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
you’d probably have your site’s files in the real root folder of your local Web server so you wouldn’t&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
run into this error. But since this is a made up example, and you’re using document-relative links (see&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
chapter 5), you’re safe. So click OK to close the warning box.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
10. Click No, and then click Next one more time.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
If you were planning to move this site onto a Web server connected to the Internet, you would select&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Yes at this stage and provide all of the information needed to move your site files to the Internet as&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
described in Chapter 16. But since this tutorial is just an exercise, you won’t be putting it up on a live&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Web server.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
11. Click Done.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Dreamweaver has successfully set up your site. You’re now ready to learn about databases and connect&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Dreamweaver to the National Exasperator online store database. (You may encounter the same&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
warning from step 9; just click OK to dismiss it.)&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Connecting Dreamweaver to a Database&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
1. From the Files Panel (Window→Files) double-click the file index.php.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The main page for the online store opens. You have to have a dynamic PHP page open, in order to&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
connect Dreamweaver to a MySQL database.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
2. Open the Databases panel by choosing Window→Databases.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The Application panel group opens.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
3. Click the plus sign (+) button at the top right of the panel. From the pop-up menu, choose MySQL&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
connection.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
4. In the Connection Name box, type connNationalEx.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
You can use any name you want as long as it doesn’t start with a number and doesn’t contain any&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
characters other than letters, numbers, and the underscore character. In this case, conn is a helpful&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
indicator that this is a database connection and makes identifying it easier if you ever need to look into&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
the underlying code of the page.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Next, you’ll tell Dreamweaver where the database is located.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
5. In the MySQL server box, type localhost.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
In this case, both the Web server and MySQL are set up on the same computer, so when the Web&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
server runs the dynamic Web pages which attempt to access the database it only needs to look at the&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
“localhost” where the MySQL Database Server is located.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
In many cases, the MySQL server provided by your Web hosting company will also be located on the&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
same server, so localhost will work when you move your pages onto your Web server. This is helpful,&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
because it means you can develop your sites locally on your computer, move them onto the Internet&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
and they should be able to connect to the database without a problem.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
However, some Web hosts put their databases on separate machines dedicated just for that one task. In&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
this case, you would need to edit the database connection, and replace localhost, which works for&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
development and testing on your own computer, with the address of the MySQL server—this might be&lt;span style=&quot;background-color: white;&quot;&gt;something like mysql.webhost.com (don’t use http://, or anything besides the server’s address.) Your&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Web hosting company can supply this information. Unfortunately this means that you need to change&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
the connection file Dreamweaver creates (this is what you’re doing right now) to include the new&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
address. Before uploading your site, open the connection file. Do this either from the databases panel&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
as described on page xx of this book or by looking in a folder name Connections located in the local&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
root folder of your site. In that folder you’ll find a file named after the connection name you supplied&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
when you created the connection—in this tutorial, that’s step 4 above so in this case the name of the&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
connection file is connNationalEx.php. Double-click this file, change localhost to the address of your&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Web host’s MySQL database server. Then upload this file to your site (see page xx for information on&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
uploading Web files). You can then open the connection file again and change the database address&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
back to localhost. This will let you continue to work and test on your local computer—just make sure&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
you don’t upload this file to the Web server, or you’ll wipe out the connection file that you customized&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
for your Web server, and your dynamic pages won’t be able to connect to the database.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
6. Type nationalEx in the username box, and nationalEx in the password box.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This is the MySQL username and password you created earlier when you set up the database.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
7. Click the Select button.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The Select Database window appears. This lets you pick which database you wish to connect to. In this&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
case it’s the National Exasperator’s online store database.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
If you get an error instead, check that you spelled localhost correctly, and that you supplied the right&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
username and password.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
8. Select nationalEx and click OK.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
9. The dialog closes and nationalEx appears in the Database box at the bottom of the window. Click the&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Test button.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
A window saying “Connection was made successfully” should appear.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
10. Click OK to close the window that appeared when you tested the connection; click OK once more to&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
close the MySQL connection box.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Behind the scenes, Dreamweaver creates a small PHP file and stores it in a folder called Connections&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
in your site’s root folder. Whenever you create a dynamic page that communicates with the database,&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Dreamweaver adds a line of code pointing to this connection file. (The file’s name reflects the&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
connection name you typed in step 4—here it’s connNationalEx.php.)&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://webdesigntipstrick.blogspot.com/feeds/8421674941488773610/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://webdesigntipstrick.blogspot.com/2012/07/php-installation.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4358669149008391889/posts/default/8421674941488773610'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4358669149008391889/posts/default/8421674941488773610'/><link rel='alternate' type='text/html' href='http://webdesigntipstrick.blogspot.com/2012/07/php-installation.html' title='PHP Installation'/><author><name>Admin</name><uri>http://www.blogger.com/profile/05350530015134205170</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZzVAzFg4Te6sNE_DcawnQg9jF25DADsOhb-yHSQ8SE_LOfeelZ5mTNES9c_oNescKQSRqPkguPEzZcYtELOzYWObTBxURPUn3JQZfcBI2VvBuumItlx8QAEk-030wnZxFsnWLVMs0OYc/s72-c/php1.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4358669149008391889.post-8328969873410720245</id><published>2012-07-11T22:55:00.002-07:00</published><updated>2012-07-11T22:55:46.067-07:00</updated><title type='text'>PHP Tutorial From beginner</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;PHP is a powerful tool for making dynamic and interactive Web pages.&lt;br /&gt;PHP is the widely-used, free, and efficient alternative to competitors such as Microsoft&#39;s ASP.&lt;br /&gt;In our PHP tutorial you will learn about PHP, and how to execute scripts on your server&lt;br /&gt;Pre-requisites&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Before you continue you should have a basic understanding of the following:&lt;br /&gt;• HTML/XHTML&lt;br /&gt;• JavaScript&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
What is PHP?&lt;br /&gt;• PHP stands for PHP: Hypertext Preprocessor&lt;br /&gt;• PHP is a server-side scripting language, like ASP&lt;br /&gt;• PHP scripts are executed on the server&lt;br /&gt;• PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.)&lt;br /&gt;• PHP is an open source software&lt;br /&gt;• PHP is free to download and use&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
What is a PHP File?&lt;br /&gt;• PHP files can contain text, HTML tags and scripts&lt;br /&gt;• PHP files are returned to the browser as plain HTML&lt;br /&gt;• PHP files have a file extension of &quot;.php&quot;, &quot;.php3&quot;, or &quot;.phtml&quot;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
What is MySQL?&lt;br /&gt;• MySQL is a database server&lt;br /&gt;• MySQL is ideal for both small and large applications&lt;br /&gt;• MySQL supports standard SQL&lt;br /&gt;• MySQL compiles on a number of platforms&lt;br /&gt;• MySQL is free to download and use&lt;br /&gt;PHP + MySQL&lt;br /&gt;• PHP combined with MySQL are cross-platform (you can develop in Windows and serve on a Unix platform)&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Why PHP?&lt;br /&gt;• PHP runs on different platforms (Windows, Linux, Unix, etc.)&lt;br /&gt;• PHP is compatible with almost all servers used today (Apache, IIS, etc.)&lt;br /&gt;• PHP is FREE to download from the official PHP resource: www.php.net&lt;br /&gt;• PHP is easy to learn and runs efficiently on the server side&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Where to Start?&lt;br /&gt;To get access to a web server with PHP support, you can:&lt;br /&gt;• Install Apache (or IIS) on your own server, install PHP, and MySQL&lt;br /&gt;• Or find a web hosting plan with PHP and MySQL support&lt;br /&gt;PHP Installation&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
What do you need?&lt;br /&gt;Most people would prefer to install a all-in-one solution:&lt;br /&gt;WampServer 2.0i [07/11/09]  for Windows platform Includes : - Apache 2.2.11 - MySQL 5.1.36 - PHP 5.3.0&lt;br /&gt;http://www.wampserver.com/en/&lt;br /&gt;http://lamphowto.com/  for Linux platform&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Already have a web server?&lt;br /&gt;If your server supports PHP you don&#39;t need to do anything.&lt;br /&gt;Just create some .php files in your web directory, and the server will parse them for you. Because it is free, most web hosts offer PHP support. However, if your server does not&lt;br /&gt;&lt;span style=&quot;background-color: white;&quot;&gt;support PHP, you must install PHP. Here is a link to a good tutorial from PHP.net on how to install PHP5:&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
http://www.php.net/manual/en/install.php&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Download PHP&lt;br /&gt;Download PHP for free here: http://www.php.net/downloads.php&lt;br /&gt;Download MySQL Database&lt;br /&gt;Download MySQL for free here: http://www.mysql.com/downloads/index.html&lt;br /&gt;Download Apache Server&lt;br /&gt;Download Apache for free here: http://httpd.apache.org/download.cgi&lt;br /&gt;Download a nice text editor [Not required]&lt;br /&gt;http://www.flos-freeware.ch/notepad2.html&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
PHP Syntax&lt;br /&gt;PHP code is executed on the server, and the plain HTML result is sent to the browser.&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Basic PHP Syntax&lt;br /&gt;A PHP scripting block always starts with &amp;lt;?php and ends with ?&amp;gt;. A PHP scripting block can be placed anywhere in the document.&lt;br /&gt;On servers with shorthand support enabled you can start a scripting block with &amp;lt;? and end with ?&amp;gt;.&lt;br /&gt;For maximum compatibility, we recommend that you use the standard form (&amp;lt;?php) rather than the shorthand form.&lt;br /&gt;&amp;lt;?php ?&amp;gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
A PHP file normally contains HTML tags, just like an HTML file, and some PHP scripting code.&lt;br /&gt;Below, we have an example of a simple PHP script which sends the text &quot;Hello World&quot; to the browser:&lt;br /&gt;&amp;lt;html&amp;gt; &amp;lt;body&amp;gt; &amp;lt;?php echo &quot;Hello World&quot;; ?&amp;gt; &amp;lt;/body&amp;gt; &amp;lt;/html&amp;gt;&lt;br /&gt;Each code line in PHP must end with a semicolon. The semicolon is a separator and is used to distinguish one set of instructions from another.&lt;br /&gt;There are two basic statements to output text with PHP: echo and print. In the example above we have used the echo statement to output the text &quot;Hello World&quot;.&lt;br /&gt;Note: The file must have a .php extension. If the file has a .html extension, the PHP code will not be executed.&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
Comments in PHP&lt;br /&gt;In PHP, we use // to make a single-line comment or /* and */ to make a large comment block.&lt;br /&gt;&amp;lt;html&amp;gt; &amp;lt;body&amp;gt; &amp;lt;?php //This is a comment /* This is a comment block */ ?&amp;gt; &amp;lt;/body&amp;gt; &amp;lt;/html&amp;gt;&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://webdesigntipstrick.blogspot.com/feeds/8328969873410720245/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://webdesigntipstrick.blogspot.com/2012/07/php-tutorial-from-beginner.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4358669149008391889/posts/default/8328969873410720245'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4358669149008391889/posts/default/8328969873410720245'/><link rel='alternate' type='text/html' href='http://webdesigntipstrick.blogspot.com/2012/07/php-tutorial-from-beginner.html' title='PHP Tutorial From beginner'/><author><name>Admin</name><uri>http://www.blogger.com/profile/05350530015134205170</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>