Archive for VTW 
 



       VTW Forum Index -> PHP
computergeek67

Everything PHP

Overview

PHP stands for PHP: Hypertext Processer. PHP is used for creating interactive web applications. And, with more knowledge, you can create massive, feature rich applications. Even this forum system that you are using now was created with PHP. So, lets get started.

Embedding PHP in HTML

One of the nice things in PHP is that you can embed commands in regular HTML. These embedded commands are written with special start and end tags. Here is an example of what these tags look like:
Code:
<?php
//php code
?>

To actually see PHP in action, create this simple script, which demonstrates how PHP and HTML can be combined:
Code:
<html>
<head></head>
<body>
<h2>Q: What is 2+2?</h2>

<?php
//print output
echo '<h2><i>A: 4</i></h2>';
?>
</body>
</html>

Save the script in your web server root as question.php, and browse to it. The page should look somethign like this:
Quote:
Q: What is 2+2?

A: 4


Writing Comments

For greater readability and to help poeple understand the code, you should add comments to your PHP code. Examples are listed below:
Code:
<?php
//this is a single line comment

/* and this is a
multiline
comment */
?>


Storing Values in Variables

Variables are the building blocks of any language. Variables can consist of both numeric and non-numeric data.

PHP variable always start out with a dollar sign ($), which is followed by the variable name. For example, $tutorial, $hi, and $you are all valid PHP variable names.

Note that PHP variables are case-sensitive meaning that $hello is different from $Hello or $HELLO.

Assigning Variable Values

To assign a variable, the use of the equal sign (=) is necessary. This operator assigns a value to a variable. To use a variable in your script, call the variable by name, and PHP will substitute its value. Here is an example:
Code:
<?php
$today = "October 21, 2007";
echo "today is $today";
?>


Saving Forum Input Variables

Forms have always been the easiest and quickest ways of adding interactivity to your site. You can use forms for emailing, comments, or asking costomers if they like your products. PHP can simplify the task of forms by using variables. Take this script for example:
Code:

<html>
<head></head>
<body>

<form action="message.php" method="post">
Enter Your Message: <input type="text" name="message" size="30">
<input type="submit" value="Send">
</form>

</body>
</html>

The method attribute of the <form> tag specifies the manner of how the data will be submitted, while the action attribute specifies the name of the PHP file (in this case, message.php), that will process the information. Here is what message.php would look like:
Code:
<?php
//retrieve from data in a variable
$input = $_POST['msg'];
//print it
echo "You said: <i>$input</i>";
?>

To see how this works, enter some data into the form ("Hello World!") and submit it. The form processer should read it and display it back to you ("you said: Hello World!").

       VTW Forum Index -> PHP
Page 1 of 1
Create your own free forum | Buy a domain to use with your forum