Friday, June 19, 2009

Different types of web hosting services based on application

If you divide the web hosting service based on it's application then you will get following different types of web hosting service - in which each one is described briefly.

1)File Hosting Service: This type of web hosting server only store files. May be simple text file, zip file, Audio file, video file, .iso file or any types of file but no web pages. User can upload file into the host server via ftp or any web interface. Most of the file hosting service offers free service with some restrictions like file size limit, captcha entry, bandwidth limit, total storage size, file expiration etc. The common example that offers file hosting service are rapidshare.com, megaupload.com.

2)Image Hosting Service: An image hosting server store images inside it and image hosting service offer users to upload images into their server. Image hosting service can offer upload image through ftp access and/or web interface. In both case you can upload multiple images at a time. Image hosting service can offer free or paid service. Free services usually comes with lots of ads in it. The common example of that offers image hosting service are flickr, picasa.

3)Video Hosting Service: As name implies that type of hosting service offers user to upload video, watching video and may be download video. The most common example of video hosting service is youtube.

4)Blog Hosting Service: Blog hosting service offers the support of authoring, editing, and publishing blog posts and comments. People can read your blog and comment on it. It also offers for image management, web syndication, and moderation of posts and comments. The most common example of blog hosting server is blogger.com and I use it to maintain my blog. You can also run your own blog hosting service and there are many free and open source weblog software that offers you to do blog hosting.

5)Social network Hosting Service: This type of hosting service offer you to store your general information, image, video and let you be connected with your friends. The common examples are facebook, myspace etc.

6)Game server hosting: A game server is a remotely or locally run server used by game clients to play multiplayer video games. Various strategic game or action games are played usually through game server. Most cases games are played over the Internet operate via a connection to a game server.

Lastly you can buy your own dedicated web server and decide which type of services you will provide. And if you want to choose many alternatives of web server and identify/compare cost between them you may see various web hosting companies searching through google.

Related Documents

Thursday, June 18, 2009

Warning: Cannot modify header information -headers already sent

Problem Description
Whenever you run a php file in the browser it shows the following warning message.
Warning: Cannot modify header information - headers already sent by (output started at E:\xampp\htdocs\mock9\pro01.php:86) in E:\xampp\htdocs\mock9\pro01.php on line 168

A variant of above error is after Warning message a function name is appended and then a error message before displaying "headers already sent".
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at E:\xampp\htdocs\mock9\index.php:4) in E:\xampp\htdocs\mock9\index.php on line 9

Cause and Problem of the Problem
This error "headers already sent" indicates that there are spaces, new lines, other garbage words or in fact any words before an opening tag <?php or after the ending tag ?>.

This same error also occur in fact case 1) if you display any output before sending any header information. Like if you display output like,
echo $query;

before sending header information like before line,
header ("location: pro02.php?pid=$pro_id");
then above error will appear.

It is important to note that with the error message
output started at E:\xampp\htdocs\mock9\pro01.php:86) in E:\xampp\htdocs\mock9\pro01.php on line 168
- It mean that the problem is inside E:\xampp\htdocs\mock9\pro01.php
- The line number that cause the problem is 86 not 168.

Similarly by error message,
output started at E:\xampp\htdocs\mock9\index.php:4) in E:\xampp\htdocs\mock9\index.php on line 9
indicates that,
- Victim file is E:\xampp\htdocs\mock9\index.php
- The problem is in line number 4.

Solution of the Problem

Wednesday, June 17, 2009

New features in Oracle database administration in 11g

This post will discuss about new features of oracle database 11g administration. Every Oracle database major release comes with new features and step by step some new features are discussed here briefly that comes with Oracle database 11g.

1)Improved Automatic Memory Management:
In 10g in case of automatic memory management we knew that if SGA_TARGET is set then all dynamic SGA components will be automatically managed and if PGA_AGGREGATE_TARGET is set then pga components will be automatically managed. But starting with oracle 11g both pga and sga memory can be managed automatically by setting only MEMORY_TARGET parameter. However you can still assign minimum sizes individually for the SGA and instance PGA.

2)New fault diagnosability infrastructure:
The fault diagnosability infrastructure are for easy diagnosis for any critical problems. After a problem has been occurred it gather necessary information against the problem and then an Incident Packaging Service packages all diagnostic data for a problem into a zip file so that you can transmit that to Oracle Support and thus reduce time to gather information about the problems.

3)Invisible Indexes:
Now in 11g you can make an index as invisible state in stead of dropping it or mark them unusable. It is very effective in order to test performance of a query to see whether removing index will improve the performance. By default an invisible index is ignored by an optimizer but is maintained during DML statements. You can change the initialization parameter to cause the optimizer to use invisible indexes.

4)Virtual Columns:
In tables you can now include virtual columns. In fact the value of a virtual column in a row is derived by evaluating an expression. The expression can include columns from the same table, constants, SQL functions, or even user-defined PL/SQL functions. You can create index and do partition on the virtual columns.

5)Enhanced Security:
In 11g now by default your password is case sensitive. So you can use mixed case password. Though by editing initialization parameter you can make password case-insensitive. More about it is discussed in the topic http://arjudba.blogspot.com/2008/04/password-is-case-sensitive-in-oracle.html

6)Database resident connection pooling:
Database resident connection pooling provides a connection pool in the database server for typical Web application usage scenarios where the application acquires a database connection, works on it for a relatively short duration, and then releases it. Database resident connection pooling significantly reduces database resources needed to support a large number of client connections and thereby boosting the scalability of both middle-tier and database tiers.

7)Tablespace level Encryption:
You can now encrypt a tablespace that contains sensitive data. Tablespace encryption is completely transparent to your application and when you encrypt a tablespace, all tablespace blocks are encrypted also.

8)Invalidation of dependent schema objects are greatly reduced:
Before 11g if we make any changes in the main object then dependent object become invalid. In 11g invalidation of dependent schema objects in response to changes in the objects they depend upon is greatly reduced and thus increasing application availability during maintenance, upgrades, and online table redefinition.

9)Enhanced automated maintenance task infrastructure:
Though in Oracle 10g you had automatic optimizer statistics gathering, Automatic Segment Advisor, and Automatic SQL Tuning Advisor. In 11g you can now exercise finer control over automated maintenance task scheduling.

10)Transparent data encryption enhanced:
Now in 11g using the transparent data encryption feature you can now encrypt SecureFile LOBs.

11)Table compression now supported in OLTP environments:
On compressed tables you can now run DML operations and adding or dropping columns of a compressed tables.

12)Query result cache in sga:
Now query results can be cached in sga memory in the result cache. The database can then use cached results to answer future executions of that query. It is also true for query fragments. As because retrieving results from the result cache is faster than rerunning a query, frequently run queries experience a significant performance improvement when their results are cached.

13)Default automatic undo management mode:
In 10g if you create database manually then the parameter UNDO_MANAGEMENT became MANUAL as by default UNDO_MANAGEMENT is manual in oracle 10g. However if you created database by dbca it makes the parameter AUTO. In 11g by default UNDO_MANAGEMENT is set to AUTO. A null value for the UNDO_MANAGEMENT initialization parameter now defaults to automatic undo management.

14)Enhancements to Oracle Database Resource Manager:

15)Enhancements to Oracle Scheduler:

16)Enhanced online index creation and rebuild:
Before oracle 11g we can do online index creation and rebuild operation but it required a DML-blocking lock at the beginning and at the end of the rebuild for a short period of time. The DML blocking lock can lock other DMLs and thus performance problem can arise while doing online index creation and rebuild operation. In 11g this lock is no longer required, making these online index operations fully transparent.

17)Tables with materialized view logs can now be redefine online:
Prior to 11g online redefinition of a table that have materialized view logs were not possible. But in 11g tables with materialized view logs can now be redefined online. Materialized view logs are now considered one of the dependent objects. So they can be copied to interim table using DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS package procedure. To know more about online redefinition have a look at Make a non-partitioned table into partition table using online redefinition .

18)Facility to make a table read only mode:
Now to avoid any update or insert or delete on a table you don't need to make whole tablespace in read only mode. In 11g with ALTER TABLE statement you can place a single table into read only mode.

19)DDL commands can wait for locks:
Prior to 11g if you have any DML operation running against the table then you can't do DDL commands on the table and instantly ORA-54 message would return as demonstrated in ORA-54 Resource Busy. But in 11g you can now set a single initialization parameter, DDL_LOCK_TIMEOUT, to specify how long a DDL command waits for the exclusive locks that it requires on internal structures before it fails. So we might not need wait for prompting further command to test whether we can run DDL commands. Oracle will check and if no DML operations DDL commands will be performed if it get resource free within DDL_LOCK_TIMEOUT time.

20)Enhancements to initialization parameter management:
There are several enhancement in the initialization parameters.

Upon startup, values of initialization parameters are written to the alert log in
such a way as to make it easy to copy and paste them to create a new PFILE.

The name and path of the PFILE or SPFILE used to start the instance is written
to the alert log so we need not to search which one is used to startup database.

Related Documents

Move your homes from one place to another

Moving from one house to another is a difficult job and sometimes fun for adults, but
it can be especially troubling for children. Though if parents deal with their children’s concerns and needs thoughtfully, much of that distress and discomfort can be avoided.

Children see moves differently than their parents do, and they benefit much less from the change in their comfortable routines- or so it seems at the time. Most often, a change in houses or communities heralds an important step forward for the adult members of the family. Normally a family moves because his father or mother got a great new job, or promotion in reward for years of hard work. It is not uncommon that someone is moving their houses to rural area in order reduce their house rent.

People may move because financial success has allowed the purchase a bigger and nicer
house in a more costly neighbourhood. They move because they can finally afford
private bedrooms for each child and perhaps a pool in the back yard or it may be vice-versa.

My friend was supposed to move from New York to Alexa and he told me it is the most cumbersome things in this living life. I then search through net and researching it about any site that offer good services and take all responsibility themselves.

I got several sites in fact many companies that do this pack and shift type jobs.

Out of them I can mention moveme.com which offer several alternatives you can choose.

You can get both a man and a van from them.

And their service that I like is they offer international moving too.

At last these types of companies make life easier in case of moving. Though you can move yourself but there is more hassle than any company offer.

The documents you might be interested
http://arjudba.blogspot.com/2009/04/why-i-dont-like-to-use-yahoo-service.html
http://arjudba.blogspot.com/2008/08/some-tips-of-mozilla-firefox.html
http://arjudba.blogspot.com/2008/11/list-of-country-calling-codes-in-world.html
http://arjudba.blogspot.com/2009/02/how-to-add-google-search-box-to-your.html

Tuesday, June 16, 2009

What is web hosting service?

Well, let me start with a simple example. You stay in a house, you/your family either buy it's space or you rent a house and you pay per month for it's space. Similarly in internet, you see the contents - contents may be text, image, video or any graphics and these contents need space to reside or in order word there must be some hosting company that is responsible to provide space for these contents.

A web hosting service is a type of internet hosting service that allows you to provide their own website accessible through internet so that they can rent their space for you. Then you can browse their site and take decision whether you will use their hosting service or in other word whether you will host your contents to them. A web hosting company can provide you space on a server they own or lease for use by their clients as well as they provide Internet connectivity with their server so that your hosted contents can be accessible through worldwide.

Based on the services they offer web hosting services can be divided through various ways.

1)Free web hosting service: In most cases they offer limited service and some of the time web hosting server wants a advertisement within your web page.

2)Shared web hosting service: Many websites share a single web hosting server.

3)Reseller web hosting: Allows client to host their server themselves. And their services vary based on reseller.

4)Virtual Dedicated Server: Resources of one server is allocated to many websites and each website owner may be responsible to manage their contents.

5)Dedicated hosting service: The user is not own the server but web hosting site dedicate a server for the user and user have the root access of the server.

6)Managed hosting service: The user does not have full control but have access to ftp their contents. The web site provider site is responsible to ensure the quality of service.

7)Colocation web hosting service: Most powerful and expensive. The hosting company provides physical space for the server and take care of the server. But the user owns the server machine and have full control of the server machine.

8)Cloud hosting: It removes single point of failure and also cost depends on the user what services they use.

9)Clustered hosting: Multiple web hosting server hosts the same content for better resource utilization. As contents reside in multiple server so Clustered Servers are the best solution for high-availability hosting, or creating a scalable web hosting solution.

10)Grid hosting: An enhancement of clustered hosting. In this case each cluster is composed on multiple nodes.

11)Home server: Privately in a home you can establish a server and can use that.

Now it is a question where I will get these hosting company in order to host my website content. In fact there are so many companies that offer web hosting service. Some popular site is godaddy.com. In fact you can so many companies that offer verious types of web hosting service. There is too many sites which are the guide for Affordable web hosting packages available online. This hosting guide has more than 200 approved web hosts with over 400 cheap web hosting packages listed.

Related Documents

Monday, June 15, 2009

ORA-00939: too many arguments -when case arguments exceed 255

Problem Description
In all Oracle 10.1g and oracle 10.2.0.1, 10.2.0.2, 10.2.0.3 whenever there is more than 255 arguments inside CASE statements then following error is returned.

ORA-00939: too many arguments for function

But surprisingly on Oracle 9.2 database the same code does not return any error.

Cause of the Problem
As we see the same code return error in 10g but it is well on 9.2. In fact this is problem of oracle 9.2 that it does not return any error. It should return error if there is more than 255 arguments inside CASE statements. In oracle 9.2 this is bug number 2909927 and this bug is fixed in oracle 10.1 and 10.2. That's why in 10.2 and 10.1 error returns if arguments exceed 255.

Up to Oracle 10.2.0.3 and earlier version, the arguments of CASE statement is limit to 255 and it does not support exceed over 255 and hence error return if it exceed. However in Oracle 10.2.0.4 and later the arguments limit of CASE statement has increased to 32767.

Solution of the Problem
Option 01:
-If you are in oracle version 10.2.0.3 or earlier then enforce a restriction so that arguments of CASE statement does not exceed 255.

-Another thing to keep in mind that CASE statements can be nested. So if possible you can nest CASE statements and thus support your application to work.

Option 02:
Upgrade to oracle database 10.2.0.4 or higher where the arguments limit of CASE statement has increased to 32767.

Related Documents
http://arjudba.blogspot.com/2008/07/types-of-sql-function-in-oracle.html
http://arjudba.blogspot.com/2009/12/oracle-object-type-exercises-varray.html
http://arjudba.blogspot.com/2009/12/practice-oracle-joins-examples.html
http://arjudba.blogspot.com/2009/12/oracle-security-practices.html
http://arjudba.blogspot.com/2009/12/exercises-with-oracle-create-table-add.html
http://arjudba.blogspot.com/2009/12/oracle-database-creation-exercises.html
http://arjudba.blogspot.com/2009/12/basic-oracle-sql-exercise.html
http://arjudba.blogspot.com/2009/08/format-model-modifiers-fx-and-fm.html
http://arjudba.blogspot.com/2009/08/number-format-models-in-oracle.html
http://arjudba.blogspot.com/2009/08/format-models-in-oracle.html
http://arjudba.blogspot.com/2009/07/sql-decode.html
http://arjudba.blogspot.com/2009/07/how-to-know-row-of-table-belong-to.html
http://arjudba.blogspot.com/2009/06/how-to-know-which-objects-are-being.html
http://arjudba.blogspot.com/2009/06/ddl-with-wait-option-in-11g.html
http://arjudba.blogspot.com/2009/06/ora-00939-too-many-arguments-when-case.html
http://arjudba.blogspot.com/2009/03/oracle-datatype-internal-code.html
http://arjudba.blogspot.com/2009/03/how-to-know-list-of-constraints-and.html
http://arjudba.blogspot.com/2009/02/how-to-know-dependent-objectswhich.html
http://arjudba.blogspot.com/2009/02/how-to-search-stringkey-value-from.html
http://arjudba.blogspot.com/2009/02/how-to-know-when-tableobjects-ddlcode.html
http://arjudba.blogspot.com/2009/02/ora-00920-invalid-relational-operator.html
http://arjudba.blogspot.com/2009/01/adding-default-value-to-column-on-table.html
http://arjudba.blogspot.com/2009/01/ora-12838-cannot-readmodify-object.html
http://arjudba.blogspot.com/2009/01/ora-01779-cannot-modify-column-which.html
http://arjudba.blogspot.com/2009/01/updating-table-based-on-another-table.html
http://arjudba.blogspot.com/2009/01/ora-00054-resource-busy-and-acquire.html
http://arjudba.blogspot.com/2008/12/troubleshoot-ora-02292-ora-02449-and.html

Call to undefined function: mysql_connect(). Please install the MySQL Connector for PHP

Error Description
In RedHat Linux, you have installed the PHP, MySQL, and Apache packages through the package manager. After starting the MySQL and Apache services through the service manager, whenever you try to view any web page that needs access the MySQL database it fails with error message,
Call to undefined function: mysql_connect(). Please install the MySQL Connector for PHP

Cause of the Problem
The mysql.so extension library does not come with the PHP or MySQL distributions. It must be installed separately by downloading any rpm package of php-mysql RPM.

Solution of the Problem
Step 01: Verify that PHP installation has been compiled with mysql support.
Write the following code and save it into a file and the load it into browser.

<?php
phpinfo();
?>

If PHP installation has been compiled with mysql support then in the browser you will see the output like,

mysql

MySQL Supportenabled
Active Persistent Links 0
Active Links 0
Client API version 5.0.51a

DirectiveLocal ValueMaster Value
mysql.allow_persistentOnOn
mysql.connect_timeout6060
mysql.default_hostno valueno value
mysql.default_passwordno valueno value
mysql.default_portno valueno value
mysql.default_socketno valueno value
mysql.default_userno valueno value
mysql.max_linksUnlimitedUnlimited
mysql.max_persistentUnlimitedUnlimited
mysql.trace_modeOffOff



If you don't see above then, you need to recompile PHP with MySQL support, or reinstall a PHP package that has it built-in.

Step 02: Check for settings inside php.ini file.
Check for php.ini file.
Be sure in linux the line
extension=mysql.so
is uncommented.

If you are on windows machine then check the line
extension=php_mysql.dll
is uncommented.

You can uncomment by simply removing preceding semi-colon of the line.
Also make sure that extension_dir is set to correctly to PHP extensions location.
Like,
extension_dir = "C:\php\ext"
This line tells PHP that all PHP extensions are located to C:\php\ext.

Step 03: Check for php-mysql package.
Check if the php-mysql package is installed on the system. To do it,
open a terminal window, and issue,
#rpm -qa | grep php

If you don't see php-mysql package then your php-mysql package is not installed.

Step 04: Install php-mysql package.
Find the php-mysql RPM for the version of PHP that is installed on your system. From google you can search for rpm packages of php-mysql and then you can download and install. Install the rpm package by,
rpm -i php-mysql-release_name.rpm

Alternative if you have yum configured then,
#yum search php //this will show all the available packages you can install.
#yum install php-mysql.i386 // this will install the mysql connector.

Step 05: Install any dependency if exists.
You might also need MySQL-shared-compat RPM if you get a dependency of libmysqlclient.so.10 error while installing.

Step 06: Restart Apache.
You are almost done. The last step is need to restart your apache server.
You can do this by two ways.
a)If you have correct path settings then,
#apachectl restart

or
b)
#/etc/rc.d/init.d/httpd restart

Related Documents

Sunday, June 14, 2009

How to edit data of Mysql using php

You have already familiar with the how to access mysql database as well as how to insert data into mysql database. How to access mysql database topic is discussed on http://arjudba.blogspot.com/2009/06/how-to-access-mysql-database-using-php.html and how to insert data into mysql database is discussed on http://arjudba.blogspot.com/2009/06/how-to-insert-data-into-mysql-database.html.

Using the insert php code which is discussed in the above link we have inserted 3 rows into basic_info table of the mysql database. Querying basic_info from mysql database yields following result,

mysql> select * from basic_info;
+---------------------------+------+----------------+
| name | age | phone |
+---------------------------+------+----------------+
| Mohammad Abdul Kasem | 65 | 01734060483 |
| Fariha Tasnuva Queen | 23 | +01912046954 |
| Mohammad Abdul Momin Arju | 23 | +8801710282272 |
+---------------------------+------+----------------+
3 rows in set (0.00 sec)

Now using php code we like to update the row based on phone number. At first in the browser it will ask phone number and then corresponding row will be displayed where user will edit information and then submit. In the mysql database that row will be updated.

Step by step whole process is discussed.

1)Create form which will take phone number from user.
The following code will create a form which will create a form that will take phone number from user and also it contains a submit button.


<html>
<body>
<form method="post">
<table style="margin-bottom: 1px; padding-left:10px;" border="0" cellpadding="0"
cellspacing="1" width="75%">
<tbody>
<tr>
<td align="right" bgcolor="#e9ece9" >Enter Phone no. to edit: </td>
<td bgcolor="#e9ece9" style="padding-left:4px;" >
<input name="phone" size="20" maxlength="20" value="<? echo $phone; ?>">
</td>
</tr>
</tbody>
</table>


<table style="margin-bottom: 1px; padding-left:455px;" border="0" cellpadding="0" cellspacing="1" width="50%">
<tbody>
<tr>
<td colspan="2" align="right" bgcolor="#dadce1" height="4">
<input name="submit" value="submit" type="submit">
</td>
</tr>
</tbody>
</table>

</body>
</html>

2)Display data from the database based on corresponding phone number.
We need php code to display data based on the phone number he typed on to browser. Below is the simple piece of code and you will understand easily the code if you have gone through my previous two posts.
It is displayed a submit button which in fact will update data into database.

<?php
#Form Variables.
$phone='';

#Database connection strings.
$ip='localhost';
$mysqluser='root';
$mysqlpass='test';
$mysqldb='test';

if(isset($_POST['submit'])){
extract($_POST);

#Build connection to mysql server.
$link= mysql_connect($ip, $mysqlUser, $mysqlPass)
or die('Could not connect: ' . mysql_error());

#Select a database to which we will perform operation.
mysql_select_db($mysqldb) or die('Could not select database');

#A query is written which will extract all information
#from basic_info table based on phone number entered.

$query = "SELECT * FROM basic_info where phone='".$phone."'";
#Execute query and store result into variable $result.
#echo $query;
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

while ($row = mysql_fetch_array($result, MYSQL_BOTH)) {
$name=$row["name"];
$age=$row["age"];
$phone=$row["phone"];
}

echo "<form method=\"post\">";
echo "<table style=\"margin-bottom: 1px;\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" width=\"60%\">\n";
echo "\t<tr>\n";
echo "\t\t<td bgcolor=\"#dadce1\" colspan=\"2\">Information of Phone:\t $phone</td>";
echo "\t\t<td bgcolor=\"#dadce1\"> <input type=\"hidden\" value='$phone' name=\"phone\" size=\"50\" ></td>";

echo "\t</tr>\n";

echo "\t<tr>\n";
echo "\t\t<td bgcolor=\"#dadce1\">Name:</td>";
echo "\t\t<td bgcolor=\"#dadce1\"> <input type=\"text\" value='$name' name=\"name\" size=\"50\" ></td>";
echo "\t</tr>\n";

echo "\t<tr>\n";
echo "\t\t<td bgcolor=\"#dadce1\">Age:</td>";
echo "\t\t<td bgcolor=\"#dadce1\"> <input type=\"text\" value='$age' name=\"age\" size=\"2\"></td>";
echo "\t</tr>\n";

echo "</table>\n";

echo "<table style=\"margin-bottom: 1px;\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" width=\"40%\">";
echo "<tr>";
echo "<td colspan=\"2\" align=\"right\" bgcolor=\"#dadce1\" height=\"4\">";
echo "<input name=\"submit02\" value=\"submit\" type=\"submit\">";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</form>";
#Free up Memory for $result.

mysql_free_result($result);
#Close database connection.
mysql_close($link);
}
?>

3)Update data into database upon pressing submit button:
Here also we need to write php code to update data into database. With a hidden field
phone number is passed to another form and using phone number data is updated in the database.
Below is the php code that will handle the update.

<?php
#Form Variables.
$phone='';
$name='';
$age='';

#Database connection strings.
$ip='localhost';
$mysqluser='root';
$mysqlpass='test';
$mysqldb='test';

if(isset($_POST['submit02'])){
$phone=$_POST["phone"];
$age=$_POST["age"];
$name=$_POST["name"];

#Build connection to mysql server.
$link= mysql_connect($ip, $mysqlUser, $mysqlPass)
or die('Could not connect: ' . mysql_error());

#Select a database to which we will perform operation.
mysql_select_db($mysqldb) or die('Could not select database');

#A query is written which will extract all information
#from basic_info table based on phone number entered.

$query = "update basic_info
set name='".$name."',
age='".$age."'
where
phone='".$phone."'";
#echo $query;
#Execute query and store result into variable $result.
#echo $query;
mysql_query($query) or die('Query failed: ' . mysql_error());
echo "Update Successfully done";
#Close database connection.
mysql_close($link);
}
?>

4)Run the code.
Total code is look like,

<?php
#Form Variables.
$name='';
$age='';
$phone='';

#Database connection strings.
$ip='localhost';
$mysqluser='root';
$mysqlpass='test';
$mysqldb='test';

if(isset($_POST['submit'])){
extract($_POST);

#Build connection to mysql server.
$link= mysql_connect($ip, $mysqlUser, $mysqlPass)
or die('Could not connect: ' . mysql_error());

#Select a database to which we will perform operation.
mysql_select_db($mysqldb) or die('Could not select database');

#Build query that will insert values into database
$query="insert into basic_info(name, age, phone) values('".$name."','".$age."','".$phone."')";

#Execute query
mysql_query($query) or die ("Error Inserting values into database");

#Close database connection.
mysql_close($link);

}
?>

<html>
<body>
<form method="post">
<table style="margin-bottom: 1px; padding-left:10px;" border="0" cellpadding="0"
cellspacing="1" width="75%">
<tbody>
<tr>
<td align="right" bgcolor="#e9ece9" >Name: </td>
<td bgcolor="#e9ece9" style="padding-left:4px;">
<input name="name" size="50" maxlength="50" width="50" value="<? echo $name; ?>">
</td>
</tr>

<tr>
<td align="right" bgcolor="#e9ece9" >Age: </td>
<td bgcolor="#e9ece9" style="padding-left:4px;">
<input name="age" size="2" maxlength="2" width="2" value="<? echo $age; ?>">
</td>
</tr>

<tr>
<td align="right" bgcolor="#e9ece9" >Phone: </td>
<td bgcolor="#e9ece9" style="padding-left:4px;" >
<input name="phone" size="20" maxlength="20" value="<? echo $phone; ?>">
</td>
</tr>
</tbody>
</table>

<table style="margin-bottom: 1px;" border="0" cellpadding="0" cellspacing="1" width="40%">
<tbody>
<tr>
<td colspan="2" align="right" bgcolor="#dadce1" height="4">
<input name="submit" value="submit" type="submit">
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>

Now save it into a file and load into browser.

It will be displayed as after submitting phone number +8801710282272,
Enter Phone no. to edit:
Information of Phone: +8801710282272
Name:
Age:


Edit name and/or age field in the browser and press submit button.

Now I changed it to,
Enter Phone no. to edit:
Information of Phone: +8801710282272
Name:
Age:


After pressing submit button it shows,
Update Successfully done

and now from database I issue query and it shows.

mysql> select * from basic_info;
+----------------------+------+----------------+
| name | age | phone |
+----------------------+------+----------------+
| Mohammad Abdul Kasem | 65 | 01734060483 |
| Fariha Tasnuva Queen | 23 | +01912046954 |
| Arju | 24 | +8801710282272 |
+----------------------+------+----------------+
3 rows in set (0.00 sec)

And row is updated.

In fact you can do same query and display output in your browser with the help of post,
http://arjudba.blogspot.com/2009/06/how-to-access-mysql-database-using-php.html
Related Documents
http://arjudba.blogspot.com/2009/06/how-to-access-mysql-database-using-php.html
http://arjudba.blogspot.com/2009/06/how-to-insert-data-into-mysql-database.html

How to insert data into mysql database using php

How to access or read data from mysql database table using php is discussed in the topic http://arjudba.blogspot.com/2009/06/how-to-access-mysql-database-using-php.html. In this post I will discuss how to insert or write data into mysql database using php.

To do that, I will use a form and user will fill out the form and upon pressing submit button the data will be inserted into mysql database. So before inserting data into mysql database we need to setup database- that means we have the database table with appropriate fields.

1)Setup Database.

Let's create a database table named basic_info for mysql test database.
D:\xampp\mysql\bin>mysql -u root -ptest
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.30-community MySQL Community Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> use test;
Database changed

mysql> create table basic_info(
-> name varchar(50),
-> age int(2),
-> phone varchar(20));
Query OK, 0 rows affected (0.22 sec)

mysql> select * from basic_info;
Empty set (0.06 sec)

2)Create a simple html form.
Below is my form which will display Name, age, phone field in the browser and a simple submit button.

<html>
<body>
<form method="post">
<table style="margin-bottom: 1px; padding-left:10px;" border="0" cellpadding="0"
cellspacing="1" width="75%">
<tbody>
<tr>
<td align="right" bgcolor="#e9ece9" >Name: </td>
<td bgcolor="#e9ece9" style="padding-left:4px;">
<input name="name" size="50" maxlength="50" width="50" value="<? echo $name; ?>">
</td>
</tr>

<tr>
<td align="right" bgcolor="#e9ece9" >Age: </td>
<td bgcolor="#e9ece9" style="padding-left:4px;">
<input name="age" size="2" maxlength="2" width="2" value="<? echo $age; ?>">
</td>
</tr>

<tr>
<td align="right" bgcolor="#e9ece9" >Phone: </td>
<td bgcolor="#e9ece9" style="padding-left:4px;" >
<input name="phone" size="20" maxlength="20" value="<? echo $phone; ?>">
</td>
</tr>
</tbody>
</table>

<table style="margin-bottom: 1px;" border="0" cellpadding="0" cellspacing="1" width="40%">
<tbody>
<tr>
<td colspan="2" align="right" bgcolor="#dadce1" height="4">
<input name="submit" value="submit" type="submit">
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>

3)Prepare php code that will insert data into database submitted into browser.

<?php
#Form Variables.
$name='';
$age='';
$phone='';

#Database connection strings.
$ip='localhost';
$mysqluser='root';
$mysqlpass='test';
$mysqldb='test';

if(isset($_POST['submit'])){
extract($_POST);

#Build connection to mysql server.
$link= mysql_connect($ip, $mysqlUser, $mysqlPass)
or die('Could not connect: ' . mysql_error());

#Select a database to which we will perform operation.
mysql_select_db($mysqldb) or die('Could not select database');

#Build query that will insert values into database
$query="insert into basic_info(name, age, phone) values('".$name."','".$age."','".$phone."')";

#Execute query
mysql_query($query) or die ("Error Inserting values into database");
}
?>

4)Combine php code with html form.

<?php
#Form Variables.
$name='';
$age='';
$phone='';

#Database connection strings.
$ip='localhost';
$mysqluser='root';
$mysqlpass='test';
$mysqldb='test';

if(isset($_POST['submit'])){
extract($_POST);

#Build connection to mysql server.
$link= mysql_connect($ip, $mysqlUser, $mysqlPass)
or die('Could not connect: ' . mysql_error());

#Select a database to which we will perform operation.
mysql_select_db($mysqldb) or die('Could not select database');

#Build query that will insert values into database
$query="insert into basic_info(name, age, phone) values('".$name."','".$age."','".$phone."')";

#Execute query
mysql_query($query) or die ("Error Inserting values into database");
}
?>

<html>
<body>
<form method="post">
<table style="margin-bottom: 1px; padding-left:10px;" border="0" cellpadding="0"
cellspacing="1" width="75%">
<tbody>
<tr>
<td align="right" bgcolor="#e9ece9" >Name: </td>
<td bgcolor="#e9ece9" style="padding-left:4px;">
<input name="name" size="50" maxlength="50" width="50" value="<? echo $name; ?>">
</td>
</tr>

<tr>
<td align="right" bgcolor="#e9ece9" >Age: </td>
<td bgcolor="#e9ece9" style="padding-left:4px;">
<input name="age" size="2" maxlength="2" width="2" value="<? echo $age; ?>">
</td>
</tr>

<tr>
<td align="right" bgcolor="#e9ece9" >Phone: </td>
<td bgcolor="#e9ece9" style="padding-left:4px;" >
<input name="phone" size="20" maxlength="20" value="<? echo $phone; ?>">
</td>
</tr>
</tbody>
</table>

<table style="margin-bottom: 1px;" border="0" cellpadding="0" cellspacing="1" width="40%">
<tbody>
<tr>
<td colspan="2" align="right" bgcolor="#dadce1" height="4">
<input name="submit" value="submit" type="submit">
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>

5)Run above code and fill fields and press submit button.
After running above code it will display following in your browser. Then I filled it like below.

Name:
Age:
Phone:


6)Query from database and be sure data is inserted.

mysql> select * from basic_info;
+---------------------------+------+----------------+
| name | age | phone |
+---------------------------+------+----------------+
| Mohammad Abdul Momin Arju | 23 | +8801710282272 |
+---------------------------+------+----------------+
1 row in set (0.03 sec)


Related Documents

How to access Mysql database using php

It is quite easy task to access mysql database using php. The detail procedure is discussed step by step.

1)Establish Connection to Mysql:
The first thing is need to establish connection to Mysql database. With the mysql_connect() function a connection is opened to Mysql server. The syntax to use mysql_connect() function is,

$link=mysql_connect('mysql_host:port', 'mysql_user', 'mysql_password')
or die('Could not connect: ' . mysql_error());


where,
mysql_connect – is a built in function to connect to a database.

mysql_host – tells the server to connect which host. May be a localhost or remote host. You can provide IP address of the server too. The default host is localhost.

port - tells the server to connect through which port. The default port is 3306.

mysql_user – this is the username for the database to connect. Default value is defined by mysql.default_user. In SQL safe mode, this parameter is ignored and the name of the user that owns the server process is used.

mysql_password – This is the mysql user password. Default value is defined by mysql.default_password. In SQL safe mode, this parameter is ignored and empty password is used.

Or die – It will return an error if we cannot connect to the database.

mysql_error - It is another mysql built in function which will return the text of the error message from previous MySQL operation. So if mysql_connect is unsuccessful mysql_error will be populated with error messages.

2)Select mysql database:
The second step is to select a database. As in the mysql server there may be many databases but we need to specify on which database we will do operation. With mysql_select_db built in function a mysql database is selected.

The usage syntax is,
mysql_select_db('my_database') or die('Could not select database');
where,
my_database - is the name of the mysql database to use.

or die - If it can't select the database it's portion will be executed.

3)Perform SQL query to access database.
Now that we have a connection to the database, we will need to build our query. We will be selecting user, password field from user table of mysql database.

So our query will look like,
$query = 'SELECT USER, PASSWORD FROM user';

Note that the query string should not end with a semicolon.

Now in order to send this query to mysql database and store the result into variable $result issue,
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

4)Display results in the browser.
We have the results of the query inside variable $result. So we need to display it into browser.

With built in function mysql_fetch_array() we can fetch a result row as an array and moves the internal data pointer ahead. We can use the following code to display result as html.

echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";


5)Free result memory:
Our task is now completed and hence we need to free up memory that is occupied by $result. By calling mysql_free_result() function we can free all memory associated with the $result. The syntax of calling the function is,

mysql_free_result($result);

6)Close Mysql database connection:
The mysql_close() closes the non-persistent connection to the MySQL server that's associated with the specified link identifier.
The syntax of closing database connection is,
mysql_close($link);

Here is our final code.

<?php

#Mysql database username is root and password is test

$link=mysql_connect('localhost', 'root', 'test')
or die('Could not connect: ' . mysql_error());

#We are selecting mysql database itself for query.
mysql_select_db('mysql') or die('Could not select database');

#A query is written to select username and password from table user.
$query = 'SELECT USER, PASSWORD FROM user';

#Execute query and store result into variable $result.
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

#Html table to display result well.
echo "<table style=\"margin-bottom: 1px;\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" width=\"100%\">\n";

#While loop to fetch row one by one.
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td bgcolor=\"#dadce1\">$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";

#Free up Memory for $result.
mysql_free_result($result);

#Close database connection.
mysql_close($link);
?>

And output displayed on the screen is,
root*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29
root
pma
magento*38EFCD3985CA39B52BDBC1C002C4DF9CB86BB039
magento*38EFCD3985CA39B52BDBC1C002C4DF9CB86BB039
momin*7CEB3FDE5F7A9C4CE5FBE610D7D8EDA62EBE5F4E
robert*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29
richard*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29
rober4t*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29


Related Documents
http://arjudba.blogspot.com/2009/05/creating-and-using-database-in-mysql.html
http://arjudba.blogspot.com/2009/05/connecting-to-and-disconnecting-from.html
http://arjudba.blogspot.com/2009/05/create-user-in-mysql.html