webhosting Web Hosting Wit.Com
Webhosting, Server and Web Site Help & Information
Internet Services
  Domain Names
  Web Hosting
  Accept Credit Cards
  SSL Certificates
  T1 Connections
 
Coding Tutorials
  HTML Tags
  HTML Code
  Style Sheets
  Javascript
  PHP Tutorial
  ASP Tutorial
  SQL (Database)
  ASP Code
  HTML Templates
 
Tips & Tricks
  Design Dos & Don'ts
  HTML Tips
  Useful Applications
  Search Engines
  My IP Lookup
 
Charts
PHP Support
  PHP Code
  PHP Scripts
  PHP Examples
  PHP MySQL
  phpMyAdmin
  PHP Scripting
  PHP Support
 
Contact Us
Home Page
 
html basic code
free html codes
PHP Coding Tutorial
Free PHP Tutorial

What is PHP?
It is Hypertext Preprocessor language. This is a side-server scripting language. It is a fantastic language that works well with simple HTML to make active and dynamically generated web sites. It can be used to make password protected web sites, set cookies, access and modify databases, send forms, emails, and more...

To use PHP you must have the PHP processor program installed on your server. If you need web hosting with PHP click here to find a server or web host with the options you need.

First save your pages as .php instead of .html , because this tells the browser to open the PHP side server for PHP functions within the web page.  You will have to load the pages on a server that is PHP ready to see them, or install PHP on to your computer.

PHP Open and Close Tags:  They must begin before and PHP script can start.
<?  add your script here

then close it here ?>

Comment Tags: This is good for editors notes and script testing.
// Text preceding two forward slashes is ignored by the browser and script


Variable tags: Put a $ sign in front of the variable name
$state = "Florida";


Semicolon Usage: You must end every PHP command with a semicolon
$city = "Tampa";

PHP Comparison Operators: These are very similar to old fashion arithmetic.
>    Greater Than
<    Less Than
==   Equal To
!=   Not Equal To
>=  Greater Than or Equal To
<=  Less Than or Equal To



Here's a PHP script that compares user input to perform a function.

You will notice that PHP can be used in conjunction with HTML.  If you are not familiar with HTML please click here for HTML Basics before proceeding.

Copy the code below onto a new .php file in Notepad or a HTML text editor.  We have web site visitors enter their age and give them a response.  It may be altered to suit your needs.  Below I will explain how it works.

<HTML>
<HEAD>
<TITLE>PHP Visitor Input and Web Site Response</TITLE>
<META name="description" content="PHP visitor input">
<META NAME="keywords" CONTENT="input form, web site reponse">
</HEAD>
<BODY BGCOLOR="white" TEXT="black" LINK="navy" VLINK="blue">
<CENTER><FONT SIZE="4">This is a basic PHP input and response form for your web site.</FONT></CENTER>
<?
$information = "
<FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">
<CENTER><BR><BR>
Your Age:
<INPUT TYPE=\"text\" NAME=\"yourage\" VALUE=\"$yourage\" SIZE=2>
<BR><BR>
<INPUT TYPE=\"hidden\" name=\"inputage\" value=\"yes\">
<INPUT TYPE=\"submit\" VALUE=\"Click to Submit\">
<INPUT TYPE=\"reset\" VALUE=\"Clear The Form\"></center>
</FORM>";
$age = 18;
if ($inputage != "yes")
{
echo "$information";
}
else if ($inputage == "yes")
{
if ($yourage >= $age)
{
print "<CENTER><BR><BR><BR>You are 18 or older and may enter.<br><br><a href=\"php_tutorial.html\">Click here for adult PHP tutorial</a></center>";
}
else
{
print "<CENTER><BR><BR><BR>You are under 18 years old and need your parents permission.<br><br><a href=\"php_tutorial.html\">Click here for childrens PHP tutorial</a></center>";
}
}
?>
</BODY>
</HTML>
 

How does this PHP script work?

First we start with the HTML. This tells the browser to start a web page in HTML.
  • <HTML>

    Then we tell the browser where the HEAD of the web page starts.
  • <HEAD>

    The Title tag shows up on the top of your browser and tells the users and search engines what your web site is about. Try to use 5 to 10 words that best describe your web page.
  • <TITLE> PHP contact form </TITLE>

    The Description Tag shows search engines what your web site is about. Try to use the best 10 to 15 words that best describe this individual web page of your web site.
  • <META  NAME="Description" CONTENT=" PHP contact form">

    The Keyword Tag is not used by many search engines anymore, but most people feel it is still of some significance.  In the Content =" area " separate the most important contents or search terms for your web site with commas.  You may want to use between 10 to 20 words.
  • <META  NAME="keywords" CONTENT="important things, kind of products, location, type of site, search phrase">

    This tells people looking at your source code who built the web site.
  • <META  NAME="author" CONTENT="Your Name Here">

    This tells people looking at your source code that your site is copyrighted.
  • <META  NAME="copyright" CONTENT="Your Name Here">

    Then we tell the browser where the HEAD of the web page ends.
  • </HEAD>

    Then we tell the browser how to set up the basics of the web page in the Body Tag.
  • <BODY TEXT="black" FACE="Arial" LINK="navy" VLINK="blue" ALINK="purple">

    This centers the sentence and and increase the font size on the page.
  • <CENTER><FONT SIZE="4">This is a basic PHP contact form for your web site.</FONT></CENTER>

    You must always use this as an opening tag to turn on PHP in your script.

  • <?

    This is creating a variable that contains the form below.
  • $information = "  

    This instructs the form to loop back to itself after completing the form and submitting it.
  • <FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">
     


    This is how you center the form and insert two line breaks to make a double space.

  • <CENTER><BR><BR>

    Here we create a variable called "name" to submit in the form, and create a box 40 characters wide for the users full name.  Within a PHP Script you must put a \ backslash before any quotes that are contained within quotes of a working script.

  • Your Full Name<BR>
    <INPUT TYPE=\"text\" NAME=\"full_name\" VALUE=\"$full_name\" SIZE=40>
    <BR><BR>


    Here we create a variable called "email_address" to submit in the form, and create a box 40 characters wide for the users email address.   See how once again we use a \ backslash before any quotes that are contained within quotes of a working script.
  • Your E-Mail Address<br>
    <INPUT TYPE=\"text\" NAME=\"email_address\" VALUE=\"$email_address\" SIZE=40>
    <br><br>


    Here we create the variable "sendform".  This is set to a value of "yes" once the form is submitted.  Once submitted the form loops back to itself and will then send the form through the mail portion of the script below.
  • <INPUT TYPE=\"hidden\" name=\"sendform\" value=\"yes\">

  • <INPUT TYPE=\"submit\" VALUE=\"Click to Submit\">

  • <INPUT TYPE=\"reset\" VALUE=\"Clear The Form\"></center>

  • </FORM>";
     


    Here is an example of a PHP script to send email from a web site.
    You will notice that PHP can be used in conjunction with HTML.  If you are not familiar with HTML please click here for HTML Basics before proceeding.

    Copy the code below onto a new .php file in Notepad or a HTML text editor.  It will make a form to send an email from your web site back to you.  It may be altered to suit your needs.  Below I will explain how it works.

    <HTML>
    <HEAD>
    <TITLE>PHP contact form</TITLE>
    <META name="description" content="PHP contact form">

    <META NAME="keywords" CONTENT="important things, kind of products, location, type of site, search phrase">
    <META  NAME="author" CONTENT="Your Name Here">
    <META  NAME="copyright" CONTENT="Your Name Here">
    </HEAD>
    <BODY BGCOLOR="white" TEXT="black" LINK="navy" VLINK="blue">
    <CENTER><FONT SIZE="4">This is a basic PHP contact form for your web site.</FONT></CENTER>
    <?
    $information = "
    <FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">
    <CENTER><BR><BR>
    Your Full Name<BR>
    <INPUT TYPE=\"text\" NAME=\"full_name\" VALUE=\"$full_name\" SIZE=40>
    <BR><BR>
    Your E-Mail Address<BR>
    <INPUT TYPE=\"text\" NAME=\"email_address\" VALUE=\"$email_address\" SIZE=40>
    <BR><BR>
    <INPUT TYPE=\"hidden\" name=\"sendform\" value=\"yes\">

    <INPUT TYPE=\"submit\" VALUE=\"Click to Submit\">
    <INPUT TYPE=\"reset\" VALUE=\"Clear The Form\"></center>
    </FORM>";
    if ($sendform != "yes") {
    echo "$information";
    } else if ($sendform == "yes") {
    $email = "PHP contact form\n";
    $email .= "Name: $full_name\n";
    $email .= "E-Mail: $email_address\n\n";
    $your_email = "Insert@YourEmail.Address";
    $form_name = "PHP contact form";
    $emailheader = "From: $email_address\n";
    $emailheader .= "Reply-To: $email_address\n\n";
    mail($your_email, $form_name, $email, $emailheader);
    echo "<CENTER><BR><BR><b>Your PHP form has been sent!<BR>This script worked if you receive an email.</b></center>";
    }
    ?>
    </BODY>
    </HTML>

    How does it work?

    Open a new document in Notepad or an HTML text editor of your choice.
    Only type the bold text and brackets following the bullets.

    First we start with the HTML. This tells the browser to start a web page in HTML.
  • <HTML>

    Then we tell the browser where the HEAD of the web page starts.
  • <HEAD>

    The Title tag shows up on the top of your browser and tells the users and search engines what your web site is about. Try to use 5 to 10 words that best describe your web page.
  • <TITLE> PHP contact form </TITLE>

    The Description Tag shows search engines what your web site is about. Try to use the best 10 to 15 words that best describe this individual web page of your web site.
  • <META  NAME="Description" CONTENT=" PHP contact form">

    The Keyword Tag is not used by many search engines anymore, but most people feel it is still of some significance.  In the Content =" area " separate the most important contents or search terms for your web site with commas.  You may want to use between 10 to 20 words.
  • <META  NAME="keywords" CONTENT="important things, kind of products, location, type of site, search phrase">

    This tells people looking at your source code who built the web site.
  • <META  NAME="author" CONTENT="Your Name Here">

    This tells people looking at your source code that your site is copyrighted.
  • <META  NAME="copyright" CONTENT="Your Name Here">

    Then we tell the browser where the HEAD of the web page ends.
  • </HEAD>

    Then we tell the browser how to set up the basics of the web page in the Body Tag.
  • <BODY TEXT="black" FACE="Arial" LINK="navy" VLINK="blue" ALINK="purple">

    This centers the sentence and and increase the font size on the page.
  • <CENTER><FONT SIZE="4">This is a basic PHP contact form for your web site.</FONT></CENTER>

    You must always use this as an opening tag to turn on PHP in your script.

  • <?

    This is creating a variable that contains the form below.
  • $information = "  

    This instructs the form to loop back to itself after completing the form and submitting it.
  • <FORM METHOD=\"POST\" ACTION=\"$PHP_SELF\">
     


    This is how you center the form and insert two line breaks to make a double space.

  • <CENTER><BR><BR>

    Here we create a variable called "name" to submit in the form, and create a box 40 characters wide for the users full name.  Within a PHP Script you must put a \ backslash before any quotes that are contained within quotes of a working script.

  • Your Full Name<BR>
    <INPUT TYPE=\"text\" NAME=\"full_name\" VALUE=\"$full_name\" SIZE=40>
    <BR><BR>


    Here we create a variable called "email_address" to submit in the form, and create a box 40 characters wide for the users email address.   See how once again we use a \ backslash before any quotes that are contained within quotes of a working script.
  • Your E-Mail Address<br>
    <INPUT TYPE=\"text\" NAME=\"email_address\" VALUE=\"$email_address\" SIZE=40>
    <br><br>


    Here we create the variable "sendform".  This is set to a value of "yes" once the form is submitted.  Once submitted the form loops back to itself and will then send the form through the mail portion of the script below.
  • <INPUT TYPE=\"hidden\" name=\"sendform\" value=\"yes\">

  • <INPUT TYPE=\"submit\" VALUE=\"Click to Submit\">

  • <INPUT TYPE=\"reset\" VALUE=\"Clear The Form\"></center>

  • </FORM>";
     


  • if ($sendform != "yes") {

  • echo "$information";
     


  • } else if ($sendform == "yes") {

  • $email = "PHP contact form\n";

  • $email .= "Name: $full_name\n";

  • $email .= "E-Mail: $email_address\n\n";

  • $your_email = "Insert@YourEmail.Address";

  • $form_name = "PHP contact form";

  • $emailheader = "From: $email_address\n";

  • $emailheader .= "Reply-To: $email_address\n\n";

  • mail($your_email, $form_name, $email, $emailheader);

  • echo "<CENTER><BR><BR><B>Your PHP form has been sent!<BR>This script worked if you receive an email.</B></CENTER>";
    }


  • ?>

  • </BODY>

  • </HTML>

    Check out this new magazine.

    PHP Architect Magazine
    PHP Architect Magazine is the first online magazine entirely devoted to the world of the PHP programming language. Each issue has a full complement of new and original articles from some of the best PHP experts in the world.

    Your Sale Price Only $18.99



    If you have any programming tips, information, or scripts you would like to add to the site e-mail it to webmaster@webhostingwit.com

    2003 Web Hosting Wit.Com and its licensors. All Rights Reserved
    Designed by Fencl Web Design