Simple PHP,AJAX application for get updates without doing any action at the client side using prototype JavaScript framework

This sample program contains 5 php files as follows;

1) config.php – This file use for manage the database access configuration.
2) add_name.php – This file use for send data to insert_name.php using AJAX.
3) insert_name.php – This file use for insert new record (which are receive from the add_name.php file) to the database.
4) view_names.php – This file use for view the database and database changes.
5) select_names.php – This file use for get all database data and print.

I have user a javascript framework called “PROTOTYPE” to develop this example (don’t worry, its not gona be a hard job for you). It is a single javascript file. So you have to download the latest version of it from (the file called prototype.js)

config.php is required for manage your database connection information easily.
// change the parameters to connect to your DB
// CHANGE ONLY $db_host, $db_name, $username, $password


add_name.php is provide a text field for enter the data (eg: names) into the database. By clicking the insert button the text form data send to the insert_name.php through ajax functions of prototype javascript framework.


function insertName(){
new Ajax.Request(‘insert.php’, {
parameters: $(‘name’).serialize(true),

insert_name.php is insert post data to the database.
// Connection to Database
// Remove HTML tag to prevent query injection
$name = strip_tags($_POST[‘name’]);

echo $name;
} else { echo ‘0’; }

view_names.php is print the data of the database. It call the select_names.php file and get the data.

DB names

new Ajax.PeriodicalUpdater(‘names’, ‘select_names.php’,
method: ‘get’,
insertion: Element.update,
frequency: 1,
decay: 1

selest_names.php is get the data from the database and print.
while ($row = mysql_fetch_array($result)){
echo “”.$row[0].””;
echo “”;



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: