What is PHP?

PHP is a server-side scripting language for creating dynamic Web pages. You create pages with PHP and HTML. When a visitor opens the page, the server processes the PHP commands and then sends the results to the visitor's browser. In addition to manipulating the content of your pages, PHP can also send HTTP headers. You can set cookies, manage authentication, and redirect users. It offers excellent connectivity to databases i.e. MySQL).

PHP goes right into your Web pages, so there's no need for a special development environment or IDE. You start a block of PHP code with <?php and end it with ?>.

start with "PHP - Echo" outputting a string

echo is a means of outputting text to the web browser. Throughout designing your PHP website you will be using the echo command more than any other.

To output a string, use PHP echo. 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.

PHP Code:

<?php
$myString = "Hello!";
echo $myString;
echo "<h5>I love using PHP!</h5>";
?>

Display:

Hello!
I love using PHP!

In the above example we output "Hello!" 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!

In our second echo statement we use echo to write a valid Header 5 HTML statement. To do this we simply put the <h5> at the beginning of the string and closed it at the end of the string. Just because you're using PHP to make web pages does not mean you can forget about HTML syntax!

Careful When Echoing Quotes!

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! Echo 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:

  • Don't use quotes inside your string
  • Escape your quotes that are within the string with a backslash. To escape a quote just place a backslash directly before the quotation mark, i.e. \"
  • Use single quotes (apostrophes) for quotes inside your string.

See our example below for the right and wrong use of echo:

PHP Code:

<?php
// This won't work because of the quotes around specialH5!
echo "<h5 class="specialH5">I love using PHP!</h5>";  

// OK because we escaped the quotes!
echo "<h5 class=\"specialH5\">I love using PHP!</h5>";  

// OK because we used an apostrophe '
echo "<h5 class='specialH5'>I love using PHP!</h5>";  
?>

If you want to output a string that includes quotations, either use an apostrophe ( ' ) or escape the quotations by placing a backslash in front of it ( \" ). The backslash will tell PHP that you want the quotation to be used within the string and NOT to be used to end echo's string.

Echoing Variables

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.

PHP Code:

<?php
$my_string = "Hello Bob.  My name is: ";
$my_number = 4;
$my_letter = a;
echo $my_string;
echo $my_number;
echo $my_letter;
?>

Display:

Hello Bob. My name is: 4a

Echoing Variables and Text Strings

You can also place variables inside of double-quoted strings (e.g. "string here and a $variable"). By putting a variable inside the quotes (" ") you are telling PHP that you want it to grab the string value of that variable and use it in the string. The example below shows an example of this cool feature.

PHP Code:

<?php
$my_string = "Hello Bob.  My name is: ";
echo "$my_string Bobettta <br />";
echo "Hi, I'm Bob.  Who are you? $my_string <br />";
echo "Hi, I'm Bob.  Who are you? $my_string Bobetta";
?>

Display:

Hello Bob. My name is: Bobetta
Hi, I'm Bob. Who are you? Hello Bob. My name is:
Hi, I'm Bob. Who are you? Hello Bob. My name is: Bobetta

By placing variables inside a string you can save yourself some time and make your code easier to read, though it does take some getting used to. Remember to use double-quotes, single-quotes will not grab the value of the string. Single-quotes will just output the variable name to the string, like )$my_string), rather than (Hello Bob. My name is: ).

A Basic start with PHP Database (mysql)

MySQL is used by the majority of web developers to store data online. Blogs, forums, images, movies, search engine information, user account information, and even entire web sites are stored, and accessed using MySQL.

Establishing the proper connection to the MySQL database is required for both functions. The initial connection is done by using the PHP function mysql_connect which links your web page to MySQL under your user authentication. Next the database is selected that holds the table we will be asking for this is done using the PHP function mysql_select_db which sets the active database for the connection.

<?php
$databasename="database_name"; // Name of the database
$tablename="table_name"; // Name of the table
$mysqladd="localhost"; // Address to the MySQL Server - Usually localhost or an IP address
$mysqluser="MySQL_username"; // Your MySQL UserName
$mysqlpass="MySQL_password"; // Your MySQL Password

//CONNECT TO MYSQL $link=mysql_connect($mysqladd,$mysqluser,$mysqlpass) or die("Database Error: " . mysql_error());
//CONNECT TO DATABASE mysql_select_db($databasename, $link) or die("Could not connect to table: " . mysql_error()); ?>

Next is the querying of the database and the building of the $results array from the MySQL $result. Built from these lines below is an array called $results that contains the resulting row(s) from the mysql_query that was performed.

<?php
$results=array();
$sql="SELECT * FROM `".$tablename."`";
$result = mysql_query($sql, $link) or die("Error: " . mysql_error()); 
while($a_row = mysql_fetch_array($result, MYSQL_ASSOC)) array_push($results, $a_row);
?>

Start uploading your page: FTP Upload

You may or may not have heard the term, FTP, but it is something that necessary tool when creating a Web site. FTP is an acronym that stands for File Transfer Protocol. An FTP client is a program that allows you to easily move files from one computer to another.

In the case of creating a Web site, this means that if you create the pages for your site on your computer, either using a text editor or some other Web page editor, then you will need to move it to the server where your site will be hosted. FTP is the main way to do this. There are many different FTP clients that you can download from the Internet. Some of these can be downloaded for free and others on a try before you buy basis.

In this scenario, we demonstrate an example using open source FTP client http://filezilla-project.org how to setup FTP client connecting to your website

Screenshot 1


Figure 1

Screenshot 2

Figure 2

Start design database: Mysql

You may design or upload your own database as per your application needed. We provide an easy online tools written in PHP intended to handle your MySql administration work over World Wide Web.

Visit http://mysql.ecd.cc and logon with your MySql username and password

Screenshot 2


Once logon you would need to select your pre-assigned default database from left panel listing which start with alphabet "db" .