Learning PHP…

August 23, 2008 at 11:06 am (Programming, Uncategorized)

PHP (recursive acronym for “PHP: Hypertext Preprocessor”) is a widely-used Open Source general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.

Example 1: Hello World (sample1.php)

<html>
<head>
<title>Example</title>
</head>
<body>
<?php
echo "Hi, I'm a PHP script!";
?>
</body>
</html>

PHP can be used on all major operating systems, including Linux, many Unix variants (including HP-UX, Solaris and OpenBSD), Microsoft Windows, Mac OS X, RISC OS, and probably others. PHP has also support for most of the web servers today. This includes Apache, Microsoft Internet Information Server, Personal Web Server, Netscape and iPlanet servers, Oreilly Website Pro server, Caudium, Xitami, OmniHTTPd, and many others. For the majority of the servers PHP has a module, for the others supporting the CGI standard, PHP can work as a CGI processor.v

Variables and Operators

$var = “Hello”; //string “hello”

$var = 3; // integer 3

$var2 = $var1; // Assigns a value of ‘PHP’ to $var2

echo $var1; // Outputs ‘PHP’

STRINGS

A string is series of characters. In PHP, a character is the same as a byte, that is, there are exactly 256 different characters possible.

<?php
echo “Hello World”;

?>

ARRAYS

An array is a special kind of variable that contains multiple values. The simplest way to create an array in PHP is to use the built-in array function:

$myarray = array(‘one’, 2, ‘3’);

$arrayvar = array(‘apple’, ‘banana’, ‘orange’);

echo $arrayvar[0]; // Outputs ‘apple’

echo $arrayvar[1]; // Outputs ‘banana’

echo $arrayvar[2]; // Outputs ‘orange’

CONTROL STRUCTURES

The most basic, and most often-used, control structure is the if-else statement.

Here’s what it looks like:

1. If condition

Ex: if($username==”admin” and password==”admin”) { echo “Hello admin! Welcome!”; }

else { echo “Invalid username or password”; }

2. While condition

Example:

$count = 1;

while ($count <= 10) {

echo “$count “;

++$count;

}

3. For Loop

Ex: for($i = 0; $i <10; $i++)

{ echo $i; }

Example:

<html>

<body><center>

<table width =”50″ border=”1“>

<?php

for($y=1; $y<=10; $y++)

{ echo “<tr><td><center><h1>$y </h1></center></td></tr>”; }

?>

</table>

</center>

</body></html>

DEALING WITH FORMS

One of the most powerful features of PHP is the way it handles HTML forms. The basic concept that is important to understand is that any form element in a form will automatically be available to your PHP scripts.

welcome.html

<form action=”welcome.php” method=”get”>

<label>First Name: <input type=”text” name=”firstname” />

</label><br />

<label>Last Name: <input type=”text” name=”lastname” />

</label><br />

<input type=”submit” value=”GO” />

</form>

welcome.php

<?php

$firstname = $_POST[‘firstname’];

$lastname = $_POST[‘lastname’];

echo “Welcome to my Website, $firstname $lastname!”;

?>

SESSION HANDLING FUNCTIONS

Session support in PHP consists of a way to preserve certain data across subsequent accesses. This enables you to build more customized applications and increase the appeal of your web site.

A visitor accessing your web site is assigned an unique id, the so-called session id. This is either stored in a cookie on the user side or is propagated in the URL.

Example:

session_start();

$_SESSION[‘username’] = $name;

To destroy a session you created:

Example: session_destroy();

UPLOADING FILE IN PHP

The <input type="file"> form element lets a user upload the entire contents of a file to your server. When a form that includes a file element is submitted, the PHP interpreter provides access to the uploaded file through the $_FILES auto-global array.

$_FILES[‘upload-name’][‘name’]: The name of the file as uploaded from the client to the server.

$_FILES[‘upload-name’][‘type’]: The MIME type of the uploaded file. Whether this variable is assigned depends on the browser capabilities.

$_FILES[‘upload-name’][‘size’]: The byte size of the uploaded file.

$_FILES[‘upload-name’][‘tmp_name’]: Once uploaded, the file will be assigned a temporary name before it is moved to its final location.

$_FILES[‘upload-name’][‘error’]: An upload status code. Despite the name, this variable will be populated even in the case of success. There are five possible values:

CONNECTING PHP TO MYSQL

1. $connect = mysql_connect(address, username, password); // address is the ip address or host name of the computer. username and password of the same username and password of your mysql server. returns true if the connection is established.

2. mysql_select_db($databasename,$connect); // databasename name of the database, $connect is the name of the connection your established see no.1.

3. mysql_query($query[, connection_id]); // $query is the sql command you want to execute;

4. mysql_close([connection id]) // To close the connection in database server.

Example:

<?php
$link = mysql_connect(‘localhost’, ‘root’, ”);
if (!$link) {
die(‘Could not connect: ‘ . mysql_error());
}
echo ‘Connected successfully’;
mysql_close($link);
?>

Permalink Leave a Comment

Greedy Relative…

August 8, 2008 at 2:15 am (Article, Uncategorized)

How can you define greedy ? “well in my case, these are the people who were allowed to BORROW a property which they didn’t pay any amount for to the owner and the government, yet without etiquette and without word of honor, they deliberately refused to remove their belongings in the time due for them to move out. ” Building their house is only permitted by the owner. But the garage is too much. But because the owner is too kind, he asked that greedy person to sign a contract that if he wants to get that piece of land pertaining to the garage he can get that without any problem.. Years passed, the owner decided to get that piece of land because he wants to build a small office in that space.. Because they refused to remove their garage, the owner filed a case against his relative. But the greedy relative also filed a case of human rights..

“Human rights? WHAT A SHAMELESS PEOPLE? How could they file a violation of human rights! To my knowledge, the violation done is them COVETING OUR PROPERTY and AND ABUSING OUR GENEROSITY! The owner, of course, never failed to spend so much on the maintenance of that lot and these greedy people only covet it!

That’s not only a sin against society but also violates God’s commandment “thou shall not covet thy neighbors property”

Plus, it is also a form of stealing!

According to republic act no 386:
http://www.chanrobles.com/civilcodeofthephilippinesbook2.htm

Title II. – OWNERSHIP

CHAPTER 1
OWNERSHIP IN GENERAL
Ownership may be exercised over things or rights. (n)

Art. 428. The owner has the right to enjoy and dispose of a thing, without other limitations than those established by law.

The owner has also a right of action against the holder and possessor of the thing in order to recover it. (348a)

Art. 429. The owner or lawful possessor of a thing has the right to exclude any person from the enjoyment and disposal thereof. For this purpose, he may use such force as may be reasonably necessary to repel or prevent an actual or threatened unlawful physical invasion or usurpation of his property. (n)

Art. 430. Every owner may enclose or fence his land or tenements by means of walls, ditches, live or dead hedges, or by any other means without detriment to servitudes constituted thereon. (388)

Art. 431. The owner of a thing cannot make use thereof in such manner as to injure the rights of a third person. (n)


Art. 433. Actual possession under claim of ownership raises disputable presumption of ownership. The true owner must resort to judicial process for the recovery of the property. (n)

Art. 434. In an action to recover, the property must be identified, and the plaintiff must rely on the strength of his title and not on the weakness of the defendant’s claim. (n)

Permalink 1 Comment