Archive for the ‘Support n Education’ Category


CREATE MySQL

How to create a database and tables at MySQL?

The CREATE DATABASE statement is used to create a database in MySQL.

Syntax

CREATE DATABASE database_name

 

To learn more about SQL, please visit our SQL tutorial.

To get PHP to execute the statement above we must use the mysql_query() function. This function is used to send a query or command to a MySQL connection.

Example

The following example creates a database called “my_db”:

<?php
$con = mysql_connect(“localhost”,”peter”,”abc123″);
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}

if (mysql_query(“CREATE DATABASE my_db”,$con))
{
echo “Database created”;
}
else
{
echo “Error creating database: ” . mysql_error();
}

mysql_close($con);
?>

 

The CREATE TABLE statement is used to create a table in MySQL.

Syntax

CREATE TABLE table_name
(
column_name1 data_type,
column_name2 data_type,
column_name3 data_type,
….

)

 

To learn more about SQL, please visit our SQL tutorial.

We must add the CREATE TABLE statement to the mysql_query() function to execute the command.

Example

The following example creates a table named “Persons”, with three columns. The column names will be “FirstName”, “LastName” and “Age”:

<?php
$con = mysql_connect(“localhost”,”peter”,”abc123″);
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}

// Create database
if (mysql_query(“CREATE DATABASE my_db”,$con))
{
echo “Database created”;
}
else
{
echo “Error creating database: ” . mysql_error();
}

// Create table
mysql_select_db(“my_db”, $con);
$sql = “CREATE TABLE Persons
(
FirstName varchar(15),
LastName varchar(15),
Age int
)”;

// Execute query
mysql_query($sql,$con);

mysql_close($con);
?>

Important: A database must be selected before a table can be created. The database is selected with the mysql_select_db() function.

Note: When you create a database field of type varchar, you must specify the maximum length of the field, e.g. varchar(15).

The data type specifies what type of data the column can hold. For a complete reference of all the data types available in MySQL, go to our complete Data Types reference.

 

PRIMARY KEY AND AUTO INCREMENT  FILEDS

Each table should have a primary key field.

A primary key is used to uniquely identify the rows in a table. Each primary key value must be unique within the table. Furthermore, the primary key field cannot be null because the database engine requires a value to locate the record.

The following example sets the personID field as the primary key field. The primary key field is often an ID number, and is often used with the AUTO_INCREMENT setting. AUTO_INCREMENT automatically increases the value of the field by 1 each time a new record is added. To ensure that the primary key field cannot be null, we must add the NOT NULL setting to the field.

Example

$sql = “CREATE TABLE Persons
(
personID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(personID),
FirstName varchar(15),
LastName varchar(15),
Age int
)”;

mysql_query($sql,$con);

 

ENJOY IT!!!

source : w3school.com


Advertisements

PHP MYSQL INTRODUCTION

What Is MySQL??

MySQL is a database.

The data in MySQL is stored in database objects called tables.

A table is a collections of related data entries and it consists of columns and rows.

Databases are useful when storing information categorically. A company may have a database with the following tables: “Employees”, “Products”, “Customers” and “Orders”.

DATABASE tables

A database most often contains one or more tables. Each table is identified by a name (e.g. “Customers” or “Orders”). Tables contain records (rows) with data.

Below is an example of a table called “Persons”:

LastName FirstName Address City
Hansen Ola Timoteivn 10 Sandnes
Svendson Tove Borgvn 23 Sandnes
Pettersen Kari Storgt 20 Stavanger

The table above contains three records (one for each person) and four columns (LastName, FirstName, Address, and City).

QUERIES

A query is a question or a request.

With MySQL, we can query a database for specific information and have a recordset returned.

Look at the following query:

SELECT LastName FROM Persons

The query above selects all the data in the “LastName” column from the “Persons” table, and will return a recordset like this:

LastName
Hansen
Svendson
Pettersen


Download MySQL Database

If you don’t have a PHP server with a MySQL Database, you can download MySQL for free here: http://www.mysql.com/downloads/index.html

Facts About MySQL Database

One great thing about MySQL is that it can be scaled down to support embedded database applications. Perhaps it is because of this reputation that many people believe that MySQL can only handle small to medium-sized systems.

The truth is that MySQL is the de-facto standard database for web sites that support huge volumes of both data and end users (like Friendster, Yahoo, Google).

Look at http://www.mysql.com/customers/ for an overview of companies using MySQL.

PHP MYSQL to connect a DATABASE

Create a Connection to a MySQL Database

Before you can access data in a database, you must create a connection to the database.

In PHP, this is done with the mysql_connect() function.

Syntax

mysql_connect(servername,username,password);

Parameter Description
servername Optional. Specifies the server to connect to. Default value is “localhost:3306”
username Optional. Specifies the username to log in with. Default value is the name of the user that owns the server process
password Optional. Specifies the password to log in with. Default is “”

Note: There are more available parameters, but the ones listed above are the most important. Visit our full PHP MySQL Reference for more details.

Example:

In the following example we store the connection in a variable ($con) for later use in the script. The “die” part will be executed if the connection fails:

<?php
$con = mysql_connect(“localhost”,”peter”,”abc123″);
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}

// some code
?>

Closing a Connection

The connection will be closed automatically when the script ends. To close the connection before, use the mysql_close() function:

<?php
$con = mysql_connect(“localhost”,”peter”,”abc123″);
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}

// some code

mysql_close($con);
?>

ENJOY IT!!!!

 

source :w3school.com


PHP SECURE EMAIL

PHP E-MAIL INJECTIONS

First, look at the PHP code from the previous chapter:

<html>
<body>

<?php
if (isset($_REQUEST[’email’]))
//if “email” is filled out, send email
{
//send email
$email = $_REQUEST[’email’] ;
$subject = $_REQUEST[‘subject’] ;
$message = $_REQUEST[‘message’] ;
mail(“someone@example.com”, “Subject: $subject”,
$message, “From: $email” );
echo “Thank you for using our mail form”;
}
else
//if “email” is not filled out, display the form
{
echo “<form method=’post’ action=’mailform.php’>
Email: <input name=’email’ type=’text’ /><br />
Subject: <input name=’subject’ type=’text’ /><br />
Message:<br />
<textarea name=’message’ rows=’15’ cols=’40’>
</textarea><br />
<input type=’submit’ />
</form>”;
}

?>
</body>
</html>

The problem with the code above is that unauthorized users can insert data into the mail headers via the input form.

What happens if the user adds the following text to the email input field in the form?

someone@example.com%0ACc:person2@example.com
%0ABcc:person3@example.com,person3@example.com,
anotherperson4@example.com,person5@example.com
%0ABTo:person6@example.com

The mail() function puts the text above into the mail headers as usual, and now the header has an extra Cc:, Bcc:, and To: field. When the user clicks the submit button, the e-mail will be sent to all of the addresses above!

PHP STOPPING E-MAIL INJECTIONS

The best way to stop e-mail injections is to validate the input.

The code below is the same as in the previous chapter, but now we have added an input validator that checks the email field in the form:

<html>
<body>
<?php
function spamcheck($field)
{
//filter_var() sanitizes the e-mail
//address using FILTER_SANITIZE_EMAIL
$field=filter_var($field, FILTER_SANITIZE_EMAIL);

//filter_var() validates the e-mail
//address using FILTER_VALIDATE_EMAIL
if(filter_var($field, FILTER_VALIDATE_EMAIL))
{
return TRUE;
}
else
{
return FALSE;
}
}

if (isset($_REQUEST[’email’]))
{//if “email” is filled out, proceed

//check if the email address is invalid
$mailcheck = spamcheck($_REQUEST[’email’]);
if ($mailcheck==FALSE)
{
echo “Invalid input”;
}
else
{//send email
$email = $_REQUEST[’email’] ;
$subject = $_REQUEST[‘subject’] ;
$message = $_REQUEST[‘message’] ;
mail(“someone@example.com”, “Subject: $subject”,
$message, “From: $email” );
echo “Thank you for using our mail form”;
}
}
else
{//if “email” is not filled out, display the form
echo “<form method=’post’ action=’mailform.php’>
Email: <input name=’email’ type=’text’ /><br />
Subject: <input name=’subject’ type=’text’ /><br />
Message:<br />
<textarea name=’message’ rows=’15’ cols=’40’>
</textarea><br />
<input type=’submit’ />
</form>”;
}
?>

</body>
</html>

In the code above we use PHP filters to validate input:

  • The FILTER_SANITIZE_EMAIL filter removes all illegal e-mail characters from a string
  • The FILTER_VALIDATE_EMAIL filter validates value as an e-mail address.

ENJOY IT!!!!!!!

source : w3schools.com




PHP COOKIES

 

what is a COOKIE?

A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user’s computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values.

 

HOW TO CREATE a COOKIE?

The setcookie() function is used to set a cookie.

Note: The setcookie() function must appear BEFORE the <html> tag.

Syntax

setcookie(name, value, expire, path, domain);

Example 1

In the example below, we will create a cookie named “user” and assign the value “Alex Porter” to it. We also specify that the cookie should expire after one hour:

 

<?php
setcookie(“user”, “Alex Porter”, time()+3600);
?>

<html>
…..

 

Note: The value of the cookie is automatically URLencoded when sending the cookie, and automatically decoded when received (to prevent URLencoding, use setrawcookie() instead).

Example 2

You can also set the expiration time of the cookie in another way. It may be easier than using seconds.

 

<?php
$expire=time()+60*60*24*30;
setcookie(“user”, “Alex Porter”, $expire);
?>

<html>
…..

 

HOW TO RETRIEVE A COOKIE VALUE??

The PHP $_COOKIE variable is used to retrieve a cookie value.

In the example below, we retrieve the value of the cookie named “user” and display it on a page:

<?php
// Print a cookie
echo $_COOKIE[“user”];

// A way to view all cookies
print_r($_COOKIE);
?>

In the following example we use the isset() function to find out if a cookie has been set:

<html>
<body>

<?php
if (isset($_COOKIE[“user”]))
echo “Welcome ” . $_COOKIE[“user”] . “!<br />”;
else
echo “Welcome guest!<br />”;
?>

</body>
</html>

 

HOW TO DELETE A COOKIE??

When deleting a cookie you should assure that the expiration date is in the past.

Delete example:

<?php
// set the expiration date to one hour ago
setcookie(“user”, “”, time()-3600);
?>

WHAT IF  A BROWSER DOESN’T  SUPPORT COOKIES

If your application deals with browsers that do not support cookies, you will have to use other methods to pass information from one page to another in your application. One method is to pass the data through forms (forms and user input are described earlier in this tutorial).

The form below passes the user input to “welcome.php” when the user clicks on the “Submit” button:

<html>
<body>

<form action=”welcome.php” method=”post”>
Name: <input type=”text” name=”name” />
Age: <input type=”text” name=”age” />
<input type=”submit” />
</form>

</body>
</html>

Retrieve the values in the “welcome.php” file like this:

<html>
<body>

Welcome <?php echo $_POST[“name”]; ?>.<br />
You are <?php echo $_POST[“age”]; ?> years old.

</body>
</html>


ENJOY IT!!

SOURCE : W3SCHOOLS.com



 


HOW TO UPLOAD FILES??

 

Look at the following HTML form for uploading files:

(create upload script)

<?php
if ($_FILES[“file”][“error”] > 0)
{
echo “Error: ” . $_FILES[“file”][“error”] . “<br />”;
}
else
{
echo “Upload: ” . $_FILES[“file”][“name”] . “<br />”;
echo “Type: ” . $_FILES[“file”][“type”] . “<br />”;
echo “Size: ” . ($_FILES[“file”][“size”] / 1024) . ” Kb<br />”;
echo “Stored in: ” . $_FILES[“file”][“tmp_name”];
}
?>

(create upload form)

<html>
<body>

<form action=”upload_file.php” method=”post”
enctype=”multipart/form-data”>
<label for=”file”>Filename:</label>
<input type=”file” name=”file” id=”file” />
<br />
<input type=”submit” name=”submit” value=”Submit” />
</form>

</body>
</html>

 

HOW TO SAVING UPLOADED FILES??

 

The temporary copied files disappears when the script ends. To store the uploaded file we need to copy it to a different location:

 

<?php
if ((($_FILES[“file”][“type”] == “image/gif”)
|| ($_FILES[“file”][“type”] == “image/jpeg”)
|| ($_FILES[“file”][“type”] == “image/pjpeg”))
&& ($_FILES[“file”][“size”] < 20000))
{
if ($_FILES[“file”][“error”] > 0)
{
echo “Return Code: ” . $_FILES[“file”][“error”] . “<br />”;
}
else
{
echo “Upload: ” . $_FILES[“file”][“name”] . “<br />”;
echo “Type: ” . $_FILES[“file”][“type”] . “<br />”;
echo “Size: ” . ($_FILES[“file”][“size”] / 1024) . ” Kb<br />”;
echo “Temp file: ” . $_FILES[“file”][“tmp_name”] . “<br />”;

if (file_exists(“upload/” . $_FILES[“file”][“name”]))
{
echo $_FILES[“file”][“name”] . ” already exists. “;
}
else
{
move_uploaded_file($_FILES[“file”][“tmp_name”],
“upload/” . $_FILES[“file”][“name”]);
echo “Stored in: ” . “upload/” . $_FILES[“file”][“name”];
}
}
}
else
{
echo “Invalid file”;
}
?>

 

ENJOY IT!!!!

 

 

 

 

 

Learning From Failure

Posted: November 20, 2009 in Support n Education

Failure is a label that often we associate with an action that did not work and so applied, the label is making us say that is not capable. This decreases our enthusiasm to become a successful person. By the time we were little, failure has no meaning, because we do not have the concept of “failure”. If we have the concept of failure, then we will not be able to speak, will not be able to write and not be able to walk. Because to speak, write and walk to the failure of countless. Likewise in the business world can also mimic our failure in childhood and we can learn from the failures. Coca-Cola had failed in the first year sales. Sales conducted by placing the Coca-Cola in the beverage in the pharmacy and 73.96 dollars spent to promote through banner ads and coupons. Failure to make Coca-Cola create awareness of other media, the mass media has more power when compared to other media and promote Coca-Cola with the atmosphere of joy. Matsushita to produce for the first time is a plug adapter. This adapter has actually proposed to the previous employer but did not receive a response. To create this product, along with four companions Matsushita took four months. After this product so no one was going to buy this product.

In 1993, Compaq which at the time as leader of the PC sales market, put through a price cut to compete with Dell. The result of Dell Computer loses 65 million dollars in the first six months, which caused nearly bankrupt. Dell learned from this failure. He tried to find other ways to sell computers. Finally, Dell made a very fundamental change in business process reengineering called. in business with the introduction of E-Commerce. In 1999, Dell can sell 1.7 million dollars per day on the website E-Commercnya. Dell shares rose 2000 percent in two years. Dell can compete with world class companies such as IBM, Compaq, HP, and Bell-Nec. Even the market share and profits continue to rise and eventually became the largest PC seller in the world.

When I started the business with friends, i made failure again. I started with the failure of a Salesman Book, telex Salesman by phone, and car materials salesmen. Primagama who only got 2 students in this campaign has done a fairly intense. CV. Wijaya, the company that serves the car care services that eventually die. Similarly, business start computer education center “IMKI”, just get AMIKOM 3 students and trusted by only 6 students. I’m with my friends trying to learn from failure, then make corrections and tried for success .

sorce: Amikom’s Journal- M.Suyanto article “belajar dari kegagalan”

The World’s Best Leaders

Posted: November 19, 2009 in Support n Education

“The leader is the first creation that determines success and failure of the organization” said Steven R. Covey. Thus the leader is the key to organizational success. Leadership review of an effective leader and what distinguishes a leader and not a leader. Definitions vary widely leaders and very much. We take the definition given by Abraham Zaleznik, and John Kotter

Abraham Zaleznik of Harvard Business School, argues that leaders and managers is very different. They differ in motiv, personal history, ways of thinking and acting. Managers tend to take the attitude of impersonal, not passive, for the purpose, while the leader took personal attitudes and activism toward the goal. Managers tend to view work as a process that allows, include a combination of people and ideas interact to define strategies and make decisions. Leaders work from a position of high risk, often temperamental they are looking for risk and danger, especially if the opportunities and rewards appear high. Managers prefer to work with people, they avoid activities alone because the activity makes them anxious. They relate to people according to the role they play in a sequence of events or in the decision making process. Leaders who consider the idea, associated with people in a more intuitive and empathetic.

John Kotter argues that leadership is different from management. Manajamen it comes to complexity, to produce order and consistency to develop formal plans, designing a strict organization and monitor the results through benchmarking with the plan. Leadership on the other hand, it comes to cope with change. Leaders establish direction by developing a vision for the future, able to synergize with the people communicate and inspire them to overcome obstacles.

The best leaders the world has the ability to dare to take risks and dangers, to appreciate the idea, communication and relationships with people with a more intuitive and empathic, able to cope with change, set direction by developing a vision for the future, able to synergize the people by communicating and inspiring them to overcome obstacles. This was done with tenderness and clarity of the heart, controlling anger, kepemaafan, justice, compassion, always praying, always consulting with emptik, working hard and surrender to God. The world’s best leaders by Michael Hart is Muhammad.

source : journal Amikom- M. Suyanto article.