Archive for category Uncategorized

Ajax Simple Application(Create CD Info with ajax)

Scripts:   Cd.html    cd_catalog.xml  getcd.php    selectcd.js this four script run form localhost to see ajax application

Cd.html

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<script type=”text/javascript” src=”selectcd.js”></script>
<title>Untitled Document</title>
</head>

<body>
<form>
Select a CD:
<select name=”cds” onchange=”showCD(this.value)”>
<option value=”Bob Dylan”>Bob Dylan</option>
<option value=”Bonnie Tyler”> Bonnie Tyler</option>
<option value=”Dolly Parton”>Dolly Parton</option>
</select>
</form>
<div id=”txtHint”><b>CD Info will be listed here…</b></div>
</body>
</html>

cd_catalog.xml

<?xml version=”1.0″ encoding=”iso-8859-1″?>

<!– Edited by XMLSpy® –>
<CATALOG>
<CD>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>

<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
</CD>
<CD>
<TITLE>Hide your heart</TITLE>
<ARTIST>Bonnie Tyler</ARTIST>
<COUNTRY>UK</COUNTRY>

<COMPANY>CBS Records</COMPANY>
<PRICE>9.90</PRICE>
<YEAR>1988</YEAR>
</CD>
<CD>
<TITLE>Greatest Hits</TITLE>
<ARTIST>Dolly Parton</ARTIST>

<COUNTRY>USA</COUNTRY>
<COMPANY>RCA</COMPANY>
<PRICE>9.90</PRICE>
<YEAR>1982</YEAR>
</CD>
<CD>
<TITLE>Still got the blues</TITLE>

<ARTIST>Gary Moore</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>Virgin records</COMPANY>
<PRICE>10.20</PRICE>
<YEAR>1990</YEAR>
</CD>

<CD>
<TITLE>Eros</TITLE>
<ARTIST>Eros Ramazzotti</ARTIST>
<COUNTRY>EU</COUNTRY>
<COMPANY>BMG</COMPANY>
<PRICE>9.90</PRICE>

<YEAR>1997</YEAR>
</CD>
<CD>
<TITLE>One night only</TITLE>
<ARTIST>Bee Gees</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>Polydor</COMPANY>

<PRICE>10.90</PRICE>
<YEAR>1998</YEAR>
</CD>
<CD>
<TITLE>Sylvias Mother</TITLE>
<ARTIST>Dr.Hook</ARTIST>
<COUNTRY>UK</COUNTRY>

<COMPANY>CBS</COMPANY>
<PRICE>8.10</PRICE>
<YEAR>1973</YEAR>
</CD>
<CD>
<TITLE>Maggie May</TITLE>
<ARTIST>Rod Stewart</ARTIST>

<COUNTRY>UK</COUNTRY>
<COMPANY>Pickwick</COMPANY>
<PRICE>8.50</PRICE>
<YEAR>1990</YEAR>
</CD>
<CD>
<TITLE>Romanza</TITLE>

<ARTIST>Andrea Bocelli</ARTIST>
<COUNTRY>EU</COUNTRY>
<COMPANY>Polydor</COMPANY>
<PRICE>10.80</PRICE>
<YEAR>1996</YEAR>
</CD>

<CD>
<TITLE>When a man loves a woman</TITLE>
<ARTIST>Percy Sledge</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Atlantic</COMPANY>
<PRICE>8.70</PRICE>

<YEAR>1987</YEAR>
</CD>
<CD>
<TITLE>Black angel</TITLE>
<ARTIST>Savage Rose</ARTIST>
<COUNTRY>EU</COUNTRY>
<COMPANY>Mega</COMPANY>

<PRICE>10.90</PRICE>
<YEAR>1995</YEAR>
</CD>
<CD>
<TITLE>1999 Grammy Nominees</TITLE>
<ARTIST>Many</ARTIST>
<COUNTRY>USA</COUNTRY>

<COMPANY>Grammy</COMPANY>
<PRICE>10.20</PRICE>
<YEAR>1999</YEAR>
</CD>
<CD>
<TITLE>For the good times</TITLE>
<ARTIST>Kenny Rogers</ARTIST>

<COUNTRY>UK</COUNTRY>
<COMPANY>Mucik Master</COMPANY>
<PRICE>8.70</PRICE>
<YEAR>1995</YEAR>
</CD>
<CD>
<TITLE>Big Willie style</TITLE>

<ARTIST>Will Smith</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>9.90</PRICE>
<YEAR>1997</YEAR>
</CD>

<CD>
<TITLE>Tupelo Honey</TITLE>
<ARTIST>Van Morrison</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>Polydor</COMPANY>
<PRICE>8.20</PRICE>

<YEAR>1971</YEAR>
</CD>
<CD>
<TITLE>Soulsville</TITLE>
<ARTIST>Jorn Hoel</ARTIST>
<COUNTRY>Norway</COUNTRY>
<COMPANY>WEA</COMPANY>

<PRICE>7.90</PRICE>
<YEAR>1996</YEAR>
</CD>
<CD>
<TITLE>The very best of</TITLE>
<ARTIST>Cat Stevens</ARTIST>
<COUNTRY>UK</COUNTRY>

<COMPANY>Island</COMPANY>
<PRICE>8.90</PRICE>
<YEAR>1990</YEAR>
</CD>
<CD>
<TITLE>Stop</TITLE>
<ARTIST>Sam Brown</ARTIST>

<COUNTRY>UK</COUNTRY>
<COMPANY>A and M</COMPANY>
<PRICE>8.90</PRICE>
<YEAR>1988</YEAR>
</CD>
<CD>
<TITLE>Bridge of Spies</TITLE>

<ARTIST>T’Pau</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>Siren</COMPANY>
<PRICE>7.90</PRICE>
<YEAR>1987</YEAR>
</CD>

<CD>
<TITLE>Private Dancer</TITLE>
<ARTIST>Tina Turner</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>Capitol</COMPANY>
<PRICE>8.90</PRICE>

<YEAR>1983</YEAR>
</CD>
<CD>
<TITLE>Midt om natten</TITLE>
<ARTIST>Kim Larsen</ARTIST>
<COUNTRY>EU</COUNTRY>
<COMPANY>Medley</COMPANY>

<PRICE>7.80</PRICE>
<YEAR>1983</YEAR>
</CD>
<CD>
<TITLE>Pavarotti Gala Concert</TITLE>
<ARTIST>Luciano Pavarotti</ARTIST>
<COUNTRY>UK</COUNTRY>

<COMPANY>DECCA</COMPANY>
<PRICE>9.90</PRICE>
<YEAR>1991</YEAR>
</CD>
<CD>
<TITLE>The dock of the bay</TITLE>
<ARTIST>Otis Redding</ARTIST>

<COUNTRY>USA</COUNTRY>
<COMPANY>Atlantic</COMPANY>
<PRICE>7.90</PRICE>
<YEAR>1987</YEAR>
</CD>
<CD>
<TITLE>Picture book</TITLE>

<ARTIST>Simply Red</ARTIST>
<COUNTRY>EU</COUNTRY>
<COMPANY>Elektra</COMPANY>
<PRICE>7.20</PRICE>
<YEAR>1985</YEAR>
</CD>

<CD>
<TITLE>Red</TITLE>
<ARTIST>The Communards</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>London</COMPANY>
<PRICE>7.80</PRICE>

<YEAR>1987</YEAR>
</CD>
<CD>
<TITLE>Unchain my heart</TITLE>
<ARTIST>Joe Cocker</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>EMI</COMPANY>

<PRICE>8.20</PRICE>
<YEAR>1987</YEAR>
</CD>
</CATALOG>

getcd.php

<?php
$q=$_GET["q"];

$xmlDoc = new DOMDocument();
$xmlDoc->load(“cd_catalog.xml”);

$x=$xmlDoc->getElementsByTagName(‘ARTIST’);

for ($i=0; $i<=$x->length-1; $i++)
{
//Process only element nodes
if ($x->item($i)->nodeType==1)
{
if ($x->item($i)->childNodes->item(0)->nodeValue == $q)
{
$y=($x->item($i)->parentNode);
}
}
}

$cd=($y->childNodes);

for ($i=0;$i<$cd->length;$i++)
{
//Process only element nodes
if ($cd->item($i)->nodeType==1)
{
echo($cd->item($i)->nodeName);
echo(“: “);
echo($cd->item($i)->childNodes->item(0)->nodeValue);
echo(“<br />”);
}
}
?>

selectcd.js

// JavaScript Document
var xmlhttp

function showCD(str)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert (“Your browser does not support AJAX!”);
return;
}
var url=”getcd.php”;
url=url+”?q=”+str;
url=url+”&sid=”+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open(“GET”,url,true);
xmlhttp.send(null);
}

function stateChanged()
{
if (xmlhttp.readyState==4)
{
document.getElementById(“txtHint”).innerHTML=xmlhttp.responseText;
}
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject(“Microsoft.XMLHTTP”);

return null;
}

—————————————————————————-end———————–

code download cdinfo

No Comments

Creating an Online Address Book

Creating an Online Address Book

Table 18.1. Address Book Table and Field Names

Table Name

Field Names

master_name

id, date_added, date_modified, f_name, l_name

address

id, master_id, date_added, date_modified, address, city, state, zipcode, type

telephone

id, master_id, date_added, date_modified, tel_number, type

fax

id, master_id, date_added, date_modified, fax_number, type

email

id, master_id, date_added, date_modified, email, type

personal_notes

id, master_id, date_added, date_modified, note

** abook(Databasename) root(user)

Scripts: mymenu.php addentry.php selentry.php delentry.php

***************************************

************** master_name ************

***************************************

create table master_name (

id int not null primary key auto_increment,

date_added datetime,

date_modified datetime,

f_name varchar (75),

l_name varchar (75) );

*******************************************

************** address ***************

********************************************

create table address (

id int not null primary key auto_increment,

master_id int not null,

date_added datetime,

date_modified datetime,

address varchar (255),

city varchar (30),

state char (2),

zipcode varchar (10),

type enum (‘home’, ‘work’, ‘other’));

*******************************************

************** telephone ***************

********************************************

create table telephone (

id int not null primary key auto_increment,

master_id int not null,

date_added datetime,

date_modified datetime,

tel_number varchar (25),

type enum (‘home’, ‘work’, ‘other’));

************** table fax ***************

***************************************

create table fax (

id int not null primary key auto_increment,

master_id int not null,

date_added datetime,

date_modified datetime,

fax_number varchar (25),

type enum (‘home’, ‘work’, ‘other’) );

************** email ***************

***************************************

create table email (

id int not null primary key auto_increment,

master_id int not null,

date_added datetime,

date_modified datetime,

email varchar (150),

type enum (‘home’, ‘work’, ‘other’) );

******** personal_notes ****** *******************************

create table personal_notes (

id int not null primary key auto_increment,

master_id int not null unique,

date_added datetime,

date_modified datetime,

note text );

  1. Address Book Menu mymenu.php

<html>

<head>

<title>My Address Book</title> </head> <body>

<h1>My Address Book</h1>

<P><strong>Management</strong>

<ul><li><a href=”addentry.php”>Add an Entry</a>

<li><a href=”delentry.php”>Delete an Entry</a></ul>

<P><strong>Viewing</strong>

<ul> <li><a href=”selentry.php”>Select a Record</a> </ul>

</body> </html>

2. Basic Record Addition Script Called addentry.php

<?php

if (($_POST[op] != “add”) || ($_GET[master_id] != “”)) {

//haven’t seen the form, so show it

$display_block = “

<h1>Add an Entry</h1>

<form method=\”post\” action=\”$_SERVER[PHP_SELF]\”>”;

if ($_GET[master_id] != “”) {

//connect to database

$conn = mysql_connect(“localhost”, “root”, “”)

or die(mysql_error());

mysql_select_db(“Abook”,$conn) or die(mysql_error());

//get first, last names for display/tests validity

$get_names = “select concat_ws(‘ ‘, f_name, l_name) as

display_name from master_name where id = $_GET[master_id]“;

$get_names_res = mysql_query($get_names) or die(mysql_error());

if (mysql_num_rows($get_names_res) == 1) {

$display_name = mysql_result($get_names_res,0,’display_name’);

}

}

if ($display_name != “”) {

$display_block .= “<P>Adding information for

<strong>$display_name</strong>:</p>”;

} else {

$display_block .= “

<P><strong>First/Last Names:</strong><br>

<input type=\”text\” name=\”f_name\” size=30 maxlength=75>

<input type=\”text\” name=\”l_name\” size=30 maxlength=75>”;

}

$display_block .= “<P><strong>Address:</strong><br>

<input type=\”text\” name=\”address\” size=30>

<P><strong>City/State/Zip:</strong><br>

<input type=\”text\” name=\”city\” size=30 maxlength=50>

<input type=\”text\” name=\”state\” size=5 maxlength=2>

<input type=\”text\” name=\”zipcode\” size=10 maxlength=10>

<P><strong>Address Type:</strong><br>

<input type=\”radio\” name=\”add_type\” value=\”home\” checked> home

<input type=\”radio\” name=\”add_type\” value=\”work\”> work

<input type=\”radio\” name=\”add_type\” value=\”other\”> other

<P><strong>Telephone Number:</strong><br>

<input type=\”text\” name=\”tel_number\” size=30 maxlength=25>

<input type=\”radio\” name=\”tel_type\” value=\”home\” checked> home

<input type=\”radio\” name=\”tel_type\” value=\”work\”> work

<input type=\”radio\” name=\”tel_type\” value=\”other\”> other

<P><strong>Fax Number:</strong><br>

<input type=\”text\” name=\”fax_number\” size=30 maxlength=25>

<input type=\”radio\” name=\”fax_type\” value=\”home\” checked> home

<input type=\”radio\” name=\”fax_type\” value=\”work\”> work

<input type=\”radio\” name=\”fax_type\” value=\”other\”> other

<P><strong>Email Address:</strong><br>

<input type=\”text\” name=\”email\” size=30 maxlength=150>

<input type=\”radio\” name=\”email_type\” value=\”home\” checked> home

<input type=\”radio\” name=\”email_type\” value=\”work\”> work

<input type=\”radio\” name=\”email_type\” value=\”other\”> other

<P><strong>Personal Note:</strong><br>

<textarea name=\”note\” cols=35 rows=5 wrap=virtual></textarea>

<input type=\”hidden\” name=\”op\” value=\”add\”>

<input type=\”hidden\” name=\”master_id\” value=\”$_GET[master_id]\”>

<p><input type=\”submit\” name=\”submit\” value=\”Add Entry\”></p>

</FORM>”;

} else if ($_POST[op] == “add”) {

//time to add to tables, so check for required fields

if ((($_POST[f_name] == “”) || ($_POST[l_name] == “”)) &&

($_POST[master_id] == “”)) {

header(“Location: addentry.php”);

exit;

}

//connect to database

$conn = mysql_connect(“localhost”, “root”, “”)

or die(mysql_error());

mysql_select_db(“abook”,$conn) or die(mysql_error());

if ($_POST[master_id] == “”) {

//add to master_name table

$add_master = “insert into master_name values (”, now(),

now(), ‘$_POST[f_name]‘, ‘$_POST[l_name]‘)”;

mysql_query($add_master) or die(mysql_error());

//get master_id for use with other tables

$master_id = mysql_insert_id();

} else {

$master_id = $_POST[master_id];

}

if (($_POST[address]) || ($_POST[city]) || ($_POST[state]) ||

($_POST[zipcode])) {

//something relevant, so add to address table

$add_address = “insert into address values (”, $master_id,

now(), now(), ‘$_POST[address]‘, ‘$_POST[city]‘,

‘$_POST[state]‘, ‘$_POST[zipcode]‘, ‘$_POST[add_type]‘)”;

mysql_query($add_address) or die(mysql_error());

}

if ($_POST[tel_number]) {

//something relevant, so add to telephone table

$add_tel = “insert into telephone values (”, $master_id,

now(), now(), ‘$_POST[tel_number]‘, ‘$_POST[tel_type]‘)”;

mysql_query($add_tel) or die(mysql_error());

}

if ($_POST[fax_number]) {

//something relevant, so add to fax table

$add_fax = “insert into fax values (”, $master_id, now(),

now(), ‘$_POST[fax_number]‘, ‘$_POST[fax_type]‘)”;

mysql_query($add_fax) or die(mysql_error());

}

if ($_POST[email]) {

//something relevant, so add to email table

$add_email = “insert into email values (”, $master_id,

now(), now(), ‘$_POST[email]‘, ‘$_POST[email_type]‘)”;

mysql_query($add_email) or die(mysql_error());

}

if ($_POST[note]) {

//something relevant, so add to notes table

$add_note = “replace into personal_notes values (”, $master_id,

now(), now(), ‘$_POST[note]‘)”;

mysql_query($add_note) or die(mysql_error());

}

$display_block = “<h1>Entry Added</h1>

<P>Your entry has been added. Would you like to

<a href=\”addentry.php\”>add another</a>?</p>”;

}

?>

<HTML>

<HEAD> <TITLE>Add an Entry</TITLE> </HEAD>

<BODY>

<?php echo $display_block; ?>

</BODY> </HTML>

3 Script Called selentry.php for Selecting and Viewing a Record

<?php

//connect to database

$conn = mysql_connect(“localhost”, “root”, “”)

or die(mysql_error());

mysql_select_db(“abook”,$conn) or die(mysql_error());

if ($_POST[op] != “view”) {

//haven’t seen the form, so show it

$display_block = “<h1>Select an Entry</h1>”;

//get parts of records

$get_list = “select id, concat_ws(‘, ‘, l_name, f_name) as display_name

from master_name order by l_name, f_name”;

$get_list_res = mysql_query($get_list) or die(mysql_error());

if (mysql_num_rows($get_list_res) < 1) {

//no records

$display_block .= “<p><em>Sorry, no records to select!</em></p>”;

} else {

//has records, so get results and print in a form

$display_block .= “

<form method=\”post\” action=\”$_SERVER[PHP_SELF]\”>

<P><strong>Select a Record to View:</strong><br>

<select name=\”sel_id\”>

<option value=\”\”>– Select One –</option>”;

while ($recs = mysql_fetch_array($get_list_res)) {

$id = $recs['id'];

$display_name = stripslashes($recs['display_name']);

$display_block .= “<option value=\”$id\”>

$display_name</option>”; }

$display_block .= “

</select>

<input type=\”hidden\” name=\”op\” value=\”view\”>

<p><input type=\”submit\” name=\”submit\”

value=\”View Selected Entry\”></p>

</FORM>”;

}

} else if ($_POST[op] == “view”) {

//check for required fields

if ($_POST[sel_id] == “”) {

header(“Location: selentry.php”);

exit;

}

//get master_info

$get_master = “select concat_ws(‘ ‘, f_name, l_name) as display_name

from master_name where id = $_POST[sel_id]“;

$get_master_res = mysql_query($get_master);

$display_name = stripslashes(mysql_result($get_master_res,

0,’display_name’));

$display_block = “<h1>Showing Record for $display_name</h1>”;

//get all addresses

$get_addresses = “select address, city, state, zipcode, type

from address where master_id = $_POST[sel_id]“;

$get_addresses_res = mysql_query($get_addresses);

if (mysql_num_rows($get_addresses_res) > 0) {

$display_block .= “<P><strong>Addresses:</strong><br>

<ul>”;

while ($add_info = mysql_fetch_array($get_addresses_res)) {

$address = $add_info[address];

$city = $add_info[city];

$state = $add_info[state];

$zipcode = $add_info[zipcode];

$address_type = $add_info[type];

$display_block .= “<li>$address $city $state $zipcode

($address_type)”;

}

$display_block .= “</ul>”;

}

//get all tel

$get_tel = “select tel_number, type from telephone where

master_id = $_POST[sel_id]“;

$get_tel_res = mysql_query($get_tel);

if (mysql_num_rows($get_tel_res) > 0) {

$display_block .= “<P><strong>Telephone:</strong><br>

<ul>”;

while ($tel_info = mysql_fetch_array($get_tel_res)) {

$tel_number = $tel_info[tel_number];

$tel_type = $tel_info[type];

$display_block .= “<li>$tel_number ($tel_type)”;

}

$display_block .= “</ul>”;

}

//get all fax

$get_fax = “select fax_number, type from fax where

master_id = $_POST[sel_id]“;

$get_fax_res = mysql_query($get_fax);

if (mysql_num_rows($get_fax_res) > 0) {

$display_block .= “<P><strong>Fax:</strong><br>

<ul>”;

while ($fax_info = mysql_fetch_array($get_fax_res)) {

$fax_number = $fax_info[fax_number];

$fax_type = $fax_info[type];

$display_block .= “<li>$fax_number ($fax_type)”;

}

$display_block .= “</ul>”;

}

//get all email

$get_email = “select email, type from email where

master_id = $_POST[sel_id]“;

$get_email_res = mysql_query($get_email);

if (mysql_num_rows($get_email_res) > 0) {

$display_block .= “<P><strong>Email:</strong><br>

<ul>”;

while ($email_info = mysql_fetch_array($get_email_res)) {

$email = $email_info[email];

$email_type = $email_info[type];

$display_block .= “<li>$email ($email_type)”;

}

$display_block .= “</ul>”;

}

//get personal note

$get_notes = “select note from personal_notes where

master_id = $_POST[sel_id]“;

$get_notes_res = mysql_query($get_notes);

if (mysql_num_rows($get_notes_res) == 1) {

$note = nl2br(stripslashes(mysql_result($get_notes_res,0,’note’)));

$display_block .= “<P><strong>Personal Notes:</strong><br>$note”;

}

$display_block .= “<P align=center>

<a href=\”addentry.php?master_id=$_POST[sel_id]\”>add info</a> …

<a href=\”$_SERVER[PHP_SELF]\”>select another</a></p>”;

}

?>

<HTML>

<HEAD> <TITLE>My Records</TITLE> </HEAD>

<BODY>

<?php echo $display_block; ?>

</BODY> </HTML>

4 Script Called delentry.php for Selecting and Deleting a Record

<?php

//connect to database

$conn = mysql_connect(“localhost”, “root”, “”)

or die(mysql_error());

mysql_select_db(“abook”,$conn) or die(mysql_error());

if ($_POST[op] != “delete”) {

//haven’t seen the form, so show it

$display_block = “<h1>Select an Entry</h1>”;

//get parts of records

$get_list = “select id, concat_ws(‘, ‘, l_name, f_name) as display_name

from master_name order by l_name, f_name”;

$get_list_res = mysql_query($get_list) or die(mysql_error());

if (mysql_num_rows($get_list_res) < 1) {

//no records

$display_block .= “<p><em>Sorry, no records to select!</em></p>”;

} else {

//has records, so get results and print in a form

$display_block .= “

<form method=\”post\” action=\”$_SERVER[PHP_SELF]\”>

<P><strong>Select a Record to Delete:</strong><br>

<select name=\”sel_id\”>

<option value=\”\”>– Select One –</option>”;

while ($recs = mysql_fetch_array($get_list_res)) {

$id = $recs['id'];

$display_name = stripslashes($recs['display_name']);

$display_block .= “<option value=\”$id\”>

$display_name</option>”;

}

$display_block .= “

</select>

<input type=\”hidden\” name=\”op\” value=\”delete\”>

<p><input type=\”submit\” name=\”submit\”

value=\”Delete Selected Entry\”></p>

</FORM>”;

}

} else if ($_POST[op] == “delete”) {

//check for required fields

if ($_POST[sel_id] == “”) {

header(“Location: delentry.php”);

exit;

}

//issue queries

$del_master = “delete from master_name where id = $_POST[sel_id]“;

mysql_query($del_master);

$del_address = “delete from address where id = $_POST[sel_id]“;

mysql_query($del_address);

$del_tel = “delete from telephone where id = $_POST[sel_id]“;

mysql_query($del_tel);

$del_fax = “delete from fax where id = $_POST[sel_id]“;

mysql_query($del_fax);

$del_email = “delete from email where id = $_POST[sel_id]“;

mysql_query($del_email);

$del_note = “delete from personal_notes where id = $_POST[sel_id]“;

mysql_query($del_master);

$display_block = “<h1>Record(s) Deleted</h1>

<P>Would you like to

<a href=\”$_SERVER[PHP_SELF]\”>delete another</a>?</p>”;

}

?>

<HTML>

<HEAD> <TITLE>My Records</TITLE>

</HEAD>

<BODY>

<?php echo $display_block; ?>

</BODY> </HTML>

No Comments

Matin Project

matinpc

To See details follows this link:


cluster2

Cluster architecture

Problem Statement

Building our own Supercomputer with Red Hat “Linux Cluster”.

Purpose of the Project:

High-availability clusters (also known as HA Clusters or Failover Clusters) are computer clusters that are implemented primarily for the purpose of providing high availability of services which the cluster provides. They operate by having redundant computers or nodes which are then used to provide service when system components fail. Normally, if a server with a particular application crashes, the application will be unavailable until someone fixes the crashed server. HA clustering remedies this situation by detecting hardware/software faults, and immediately restarting the application on another system without requiring administrative intervention, a process known as Failover.

To See details follows this link:

No Comments

Working with Databases(PHP & MySQL)

Working with Databases(PHP & MySQL)

Creating a Database Using MySQL:

At the mysql> prompt that appears, enter SELECT VERSION(), CURRENT_DATE; to confirm that MySQL is working:

mysql> SELECT VERSION(), CURRENT_DATE;

+---------------+--------------+
| VERSION()     | CURRENT_DATE |
+---------------+--------------+
| 5.0.20a       | 2009-08-06   |
+---------------+--------------+  [1 row in set (0.05 sec)]
Want to see what databases MySQL already comes with? Enter the SHOW DATABASES command, and we'll get something like this:
mysql> SHOW DATABASES;
+----------+
| Database |
+----------+
| mysql    |
| test     |
| ice      |
|  iu      |
| matin    |
+----------+[2 rows in set (0.01 sec)]
MySQL comes with two databases built-inmysql, which holds administrative data for MySQL, and test, which is a sample database. To store data about a variety of fruits and vegetables, we might create a new database named, say, "produce," with the CREATE DATABASE command:
mysql> CREATE DATABASE produce;
Query OK, 1 row affected (0.01 sec)
To make this database the default one to work with, enter the USE produce command:
mysql> USE produce
Database changed
Are there any tables in the produce database yet? Try the SHOW TABLES command:
mysql> SHOW TABLES;
Empty set (0.01 sec)
The response is "Empty set," which means there are no tables yet. To create a table named fruit, we need to create its data fields. There are various data types for fields; here are a few (we'll use strings in this example):
  1. VARCHAR(length). Creates a variable length string
  2. INT. Creates an integer
  3. DECIMAL(totaldigits, decimalplaces). Creates a decimal value
  4. DATETIME. Creates a date and time object, such as 2009-8-15 20:00:00

Here’s how to create the fruit table with name and number fields, both stored in strings:

mysql> CREATE TABLE fruit (name VARCHAR(20), number VARCHAR(20));

Query OK, 0 rows affected (0.13 sec)
mysql> SHOW TABLES;
+-------------------+
| Tables_in_produce |
+-------------------+
| fruit             |
+-------------------+[1 row in set (0.00 sec)]
To get a description of this new table, use the DESCRIBE command:
mysql> DESCRIBE fruit;
+--------+-------------+------+-----+---------+-------+
| Field  | Type        | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| name   | varchar(20) | YES  |     | NULL    |       |
| number | varchar(20) | YES  |     | NULL    |       |
+--------+-------------+------+-----+---------+-------+[2 rows in set (0.01 sec)]
Switch to the produce database and use INSERT to load the data into the fruit table:

mysql> USE produce

Database changed

mysql> INSERT INTO fruit VALUES (‘apples’, ’1020′);

Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO fruit VALUES (‘oranges’, ’3329′);

Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO fruit VALUES (‘bananas’, ’8582′);

Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO fruit VALUES (‘pears’, ’235′);

Query OK, 1 row affected (0.00 sec)

That’s it; we can list the data in this table with SELECT to confirm that everything’s as it should be, and then end the session with quit, completing our new database table:

mysql> SELECT * FROM fruit;

+———+——–+

| name | number |

+———+——–+

| apples | 1020 |

| oranges | 3329 |

| bananas | 8582 |

| pears | 235 |

+———+——–+ —— [4 rows in set (0.00 sec)]

Displaying a Data Table(PHP action in a browser.)

We’re ready to see some SQL and PHP action in a browser. Here, we’re going to extract the fruit table from the produce database and display its data in an HTML table. We’ll start by connecting, selecting the database, and getting an object named $result that corresponds to the fruit table:

$connection = mysql_connect("localhost","root","")
    or die ("Couldn't connect to server");
$db = mysql_select_db("produce", $connection)
    or die ("Couldn't select database");
 
$query = "SELECT * FROM fruit";
$result = mysql_query($query)
     or die("Query failed: " . mysql_error());

Now we can use the mysql_fetch_array function to get successive rows from the table in a while loop and get the name and number fields from each row by name like this:
while ($row = mysql_fetch_array($result))
{
    echo "<TR>";
    echo "<TD>", $row['name'], "</TD><TD>", $row['number'], "</TD>";
    echo "</TR>";  }
Example 1-1. Displaying a database table, phpdatatable.php
<HTML>
    <HEAD><TITLE>Displaying tables with MySQL</TITLE> </HEAD>
    <BODY>    <CENTER><H1>Displaying tables with MySQL</H1>
            <?php
                 $connection = mysql_connect("localhost","root","")
                     or die ("Couldn't connect to server");
                 $db = mysql_select_db("produce", $connection)
                     or die ("Couldn't select database");
 
                 $query = "SELECT * FROM fruit";
                 $result = mysql_query($query)
                      or die("Query failed: ".mysql_error());
 
                 echo "<TABLE BORDER='1'>";            echo "<TR>";
                 echo "<TH>Name</TH><TH>Number</TH>";  echo "</TR>";
 
                 while ($row = mysql_fetch_array($result))
                 {       echo "<TR>";
       echo "<TD>", $row['name'], "</TD><TD>",$row['number'],”</td>”;    
       echo "</TR>";                 }
      echo "</TABLE>";
                 mysql_close($connection);
             ?>         </CENTER></BODY></HTML>

Updating Database Useing PHP Scripts:

Now we can update the value in the pears row of the fruit table like this, where we’re setting the value of the number field to 234:

$query = "UPDATE fruit SET number = 234 WHERE name = 'pears'";
$result = mysql_query($query)
    or die("Query failed: ".mysql_error());
Example 1-2. Updating database data, phpdataupdate.php
<HTML>
    <HEAD> <TITLE>Updating database data</TITLE> </HEAD>

    <BODY><CENTER> <H1>Updating database data</H1>
      <?php
          $connection = mysql_connect("localhost","root","")
                     or die ("Couldn't connect to server");
          $db = mysql_select_db("produce",$connection)
                     or die ("Couldn't select database");
          $query = "UPDATE fruit SET number = 234 WHERE name =
                     'pears'";
          $result = mysql_query($query)
                      or die("Query failed: ".mysql_error());
          $query = "SELECT * FROM fruit";
          $result = mysql_query($query)
                      or die("Query failed: " . mysql_error());
            echo "<TABLE BORDER='1'>";           echo "<TR>";
            echo "<TH>Name</TH><TH>Number</TH>"; echo "</TR>";
       while ($row = mysql_fetch_array($result))
                 {
            echo "<TR>";
            echo "<TD>", $row['name'], "</TD><TD>",$row['number'], "</TD>";
            echo "</TR>";                 }
            echo "</TABLE>";
        mysql_close($connection);
     ?>         </CENTER> </BODY></HTML>

Inserting New Data Useing PHP Scripts:

To create a new row for apricots, we can use the SQL INSERT statement like this:

$query = "INSERT INTO fruit (name, number) VALUES('apricots',
    '203')";.......    

Then we execute this new SQL query to insert the new row:

$query = "INSERT INTO fruit (name, number) VALUES('apricots',
    '203')";
$result = mysql_query($query)
    or die("Query failed: " . mysql_error());
Example 1-3. Inserting new data, phpdatainsert.php
<HTML>
    <HEAD><TITLE> Inserting new data</TITLE></HEAD>
    <BODY>        <CENTER><H1>Inserting new data</H1>
            <?php
                 $connection = mysql_connect("localhost","root","")
                     or die ("Couldn't connect to server");
                 $db = mysql_select_db("produce",$connection)
                     or die ("Couldn't select database");
 
                 $query = "INSERT INTO fruit (name, number) VALUES('apricots',
                     '203')";
                 $result = mysql_query($query)
                      or die("Query failed: " . mysql_error());
                 $query = "SELECT * FROM fruit";
                 $result = mysql_query($query)
                      or die("Query failed: " . mysql_error());
 
                 echo "<TABLE BORDER='1'>";
                 echo "<TR>";
                 echo "<TH>Name</TH><TH>Number</TH>";
                 echo "</TR>";
                 while ($row = mysql_fetch_array($result))
                 {
                     echo "<TR>";
                     echo "<TD>", $row['name'], "</TD><TD>",
                                  $row['number'], "</TD>";
                     echo "</TR>";
                 }
                 echo "</TABLE>";
                 mysql_close($connection);
             ?>
         </CENTER></BODY></HTML>

Deleting Data(Useing PHP Scripts):

Then we simply execute that new SQL query to delete the apricots row:

$query = "DELETE FROM fruit WHERE name = 'apricots'";
$result = mysql_query($query)
    or die("Query failed: " . mysql_error());
Example 1-4. Deleting data, phpdatadelete.php
<HTML>
    <HEAD><TITLE>Displaying tables with MySQL</TITLE>  </HEAD>

    <BODY>
        <CENTER> <H1>Displaying tables with MySQL</H1>
            <?php
                 $connection = mysql_connect("localhost","root","")
                     or die ("Couldn't connect to server");
                 $db = mysql_select_db("produce",$connection)
                     or die ("Couldn't select database");
 
                 $query = "DELETE FROM fruit WHERE name = 'apricots'";
                 $result = mysql_query($query)
                      or die("Query failed: " . mysql_error());
 
                 $query = "SELECT * FROM fruit";
                 $result = mysql_query($query)
                      or die("Query failed: " . mysql_error());
 
                 echo "<TABLE BORDER='1'>";            echo "<TR>";
                 echo "<TH>Name</TH><TH>Number</TH>";  echo "</TR>";
 
                 while ($row = mysql_fetch_array($result))
                 {
                     echo "<TR>";
                     echo "<TD>", $row['name'], "</TD><TD>",
                                  $row['number'], "</TD>";
                     echo "</TR>";
                 }
 
                 echo "</TABLE>";
                 mysql_close($connection);
 
             ?>         </CENTER></BODY></HTML>

Creating a New Table(Useing PHP Scripts):

To create a new table, use the CREATE TABLE SQL statement, as here, where we’re configuring the name and number fields in the new vegetables table:

$query = "CREATE TABLE vegetables (name VARCHAR(20), number
    VARCHAR(20))";
$result = mysql_query($query)
    or die("Query failed: " . mysql_error());
Now we can insert data into the new vegetables table with INSERT:
$query = "INSERT INTO vegetables (name, number) VALUES('corn',
    '2083')";
$result = mysql_query($query)
    or die("Query failed: " . mysql_error());
Example 1-5. Creating a new table, phpdatacreate.php
<HTML>
    <HEAD> <TITLE>Creating a new table</TITLE> </HEAD>
    <BODY>
        <CENTER><H1>Creating a new table</H1>
            <?php
                 $connection = mysql_connect("localhost","root","")
                     or die ("Couldn't connect to server");
                 $db = mysql_select_db("produce",$connection)
                     or die ("Couldn't select database");
 
                 $query = "CREATE TABLE vegetables (name VARCHAR(20),
                     number VARCHAR(20))";
                 $result = mysql_query($query)
                      or die("Query failed: " . mysql_error());
 
                 $query = "INSERT INTO vegetables (name, number) VALUES(
                     'corn', '2083')";
                 $result = mysql_query($query)
                      or die("Query failed: " . mysql_error());
 
                 $query = "INSERT INTO vegetables (name, number)
                     VALUES('spinach', '1993')";
                 $result = mysql_query($query)
                      or die("Query failed: " . mysql_error());
 
                 $query = "INSERT INTO vegetables (name, number)
                     VALUES('beets', '437')";
                 $result = mysql_query($query)
                      or die("Query failed: " . mysql_error());
 
                 $query = "SELECT * FROM vegetables";
                 $result = mysql_query($query)
                      or die("Query failed: " . mysql_error());
 
                 echo "<TABLE BORDER='1'>";
                 echo "<TR>";
                 echo "<TH>Name</TH><TH>Number</TH>";
                 echo "</TR>";
 
                 while ($row = mysql_fetch_array($result))
                 {
                     echo "<TR>";
                     echo "<TD>", $row['name'], "</TD><TD>",
                                  $row['number'], "</TD>";
                     echo "</TR>";
                 }
                 echo "</TABLE>";
 
                 mysql_close($connection);
             ?>
         </CENTER></BODY></HTML>

Creating a Database from PHP:

We can even create a whole new database from PHP. Here’s an example, where we’re creating a database named foods using the CREATE DATABASE command:

$query = "CREATE DATABASE IF NOT EXISTS foods";
$result = mysql_query($query)
    or die("Query failed: " . mysql_error());
 
And we'll add a new table to this database, snacks:
$db = mysql_select_db("foods", $connection)
    or die ("Couldn't select database");
 
$query = "CREATE TABLE snacks (name VARCHAR(20), number
    VARCHAR(20))";
$result = mysql_query($query)
    or die("Query failed: " . mysql_error());

Example 1-6. Creating a new database, phpdatacreatedb.php
<HTML>
    <HEAD><TITLE>Creating a new database</TITLE> </HEAD>
    <BODY>   <CENTER><H1>Creating a new database</H1>
            <?php
                 $connection = mysql_connect("localhost","root","")
                     or die ("Couldn't connect to server");
 
                 $query = "CREATE DATABASE IF NOT EXISTS foods";
                 $result = mysql_query($query)
                      or die("Query failed: " . mysql_error());
 
                 $db = mysql_select_db("foods", $connection)
                     or die ("Couldn't select database");
 
                 $query = "CREATE TABLE snacks (name VARCHAR(20), number
                     VARCHAR(20))";
                 $result = mysql_query($query)
                      or die("Query failed: " . mysql_error());
 
                 $query = "INSERT INTO snacks (name, number) VALUES('tacos',
                     '2843')";
                 $result = mysql_query($query)
                      or die("Query failed: " . mysql_error());
                $query = "INSERT INTO snacks (name, number) VALUES('pizza',
                     '1955')";
                 $result = mysql_query($query)
                      or die("Query failed: " . mysql_error());
                 $query = "INSERT INTO snacks (name, number)
                     VALUES('cheeseburgers', '849')";
                 $result = mysql_query($query)
                      or die("Query failed: " . mysql_error());
 
                 $query = "SELECT * FROM snacks";
                 $result = mysql_query($query)
                      or die("Query failed: " . mysql_error());
 
                 echo "<TABLE BORDER='1'>";
                 echo "<TR>";
                 echo "<TH>Name</TH><TH>Number</TH>";
                 echo "</TR>";
 
                 while ($row = mysql_fetch_array($result))
                 {
                     echo "<TR>";
                     echo "<TD>", $row['name'], "</TD><TD>",
                                  $row['number'], "</TD>";
                     echo "</TR>";
                 }
                 echo "</TABLE>";
 
                 mysql_close($connection);
 
             ?>
         </CENTER> </BODY></HTML>

Sorting Data

Then when we read wer data, use the ORDER BY clause to indicate what field we want to sort on. For example, if we want to sort by name of the various fruits, use this statement:

$query = "SELECT * FROM fruit ORDER BY name";
 
$result = mysql_query($query)
    or die("Query failed: ".mysql_error());
Example 1-7. Sorting data, phpdatasort.php
<HTML>
    <HEAD> <TITLE>Sorting data</TITLE>  </HEAD>

    <BODY> <CENTER> <H1> Sorting data</H1>
            <?php
                 $connection = mysql_connect("localhost","root","")
                     or die ("Couldn't connect to server");
 
                 $db = mysql_select_db("produce",$connection)
                     or die ("Couldn't select database");
 
                 $query = "SELECT * FROM fruit ORDER BY name";
                 $result = mysql_query($query)
                      or die("Query failed: ".mysql_error());
 
                 echo "<TABLE BORDER='1'>";
                 echo "<TR>";
                 echo "<TH>Name</TH><TH>Number</TH>";
                 echo "</TR>";
 
                 while ($row = mysql_fetch_array($result))
                 {
                     echo "<TR>";
                     echo "<TD>", $row['name'], "</TD><TD>",
                                  $row['number'], "</TD>";
                     echo "</TR>";
                 }
                 echo "</TABLE>";
 
                 mysql_close($connection);
 
             ?>         </CENTER></BODY></HTML>

Displaying a Table with DB:

Now we can use the query method of the $db object to execute a SQL query like this one, which reads the entire fruit table:

require 'DB.php';
$db = DB::connect('mysql://root:@localhost/produce');
$query = "SELECT * FROM fruit";
$result = $db->query($query);
Example 1-8. Displaying a table with DB, phpdb.php
<HTML>
    <HEAD><TITLE>Using DB to display a table</TITLE>   </HEAD>
    <BODY>        <CENTER> <H1>Using DB to display a table</H1>
            <?php
                require 'DB.php';
                $db = DB::connect('mysql://root:@localhost/produce');
                $query = "SELECT * FROM fruit";
                $result = $db->query($query);
 
                echo "<TABLE BORDER='1'>";
                echo "<TR>";
                echo "<TH>Name</TH><TH>Number</TH>";
                echo "</TR>";
 
                while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
                {
                    echo "<TR>";
                    echo "<TD>", $row['name'], "</TD><TD>", $row['number'],
                        "</TD>";
                    echo "</TR>";
                }
                echo "</TABLE>";
            ?>
        </CENTER> </BODY></HTML>

Inserting New Data with DB:

And now we can execute this query with the $db->query method:

$db = DB::connect('mysql://root:@localhost/produce');
 
$query = "INSERT INTO fruit (name, number)
    VALUES('apricots', '203')";
 
$result = $db->query($query);
Example 1-9. Inserting database data, phpdbinsert.php
<HTML>
    <HEAD> <TITLE>Using DB to insert data</TITLE>  </HEAD>
    <BODY>
        <CENTER><H1>Using DB to insert data</H1>
            <?php
                require 'DB.php';
                $db = DB::connect('mysql://root:@localhost/produce');
 
                $query = "INSERT INTO fruit (name, number)
                    VALUES('apricots', '203')";
 
                $result = $db->query($query);
                $query = "SELECT * FROM fruit";
                $result = $db->query($query);
 
                echo "<TABLE BORDER='1'>";
                echo "<TR>";
                echo "<TH>Name</TH><TH>Number</TH>";
                echo "</TR>";
 
                while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
                {
                    echo "<TR>";
                    echo "<TD>", $row['name'], "</TD><TD>",
                                 $row['number'], "</TD>";
                    echo "</TR>";
                }
                echo "</TABLE>";
            ?>
        </CENTER> </BODY></HTML>

Updating Data with DB

Here’s another oneupdating data with the DB module. As before, we’ll reduce the number of pears in the fruit table from 235 to 234. Because we’ve got a handle on using SQL with the DB module, there’s no problem here either; just set up the correct SQL query and then execute that query:

$query = "UPDATE fruit SET number = 234 WHERE name = 'pears'";
$result = $db->query($query);
Example 1-10. Updating database data, phpdbupdate.php
<HTML>
    <HEAD><TITLE>Using DB to update data </TITLE>  </HEAD>

    <BODY>
        <CENTER><H1>Using DB to update data</H1>
            <?php
                require 'DB.php';
                $db = DB::connect('mysql://root:@localhost/produce');
                $query = "UPDATE fruit SET number = 234 WHERE name = 'pears'";
                $result = $db->query($query);
                $query = "SELECT * FROM fruit";
                $result = $db->query($query);
 
                echo "<TABLE BORDER='1'>";           echo "<TR>";
                echo "<TH>Name</TH><TH>Number</TH>"; echo "</TR>";
 
             while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
                {
                    echo "<TR>";
                    echo "<TD>", $row['name'], "</TD><TD>",
                                 $row['number'], "</TD>";
                    echo "</TR>";
                }
                echo "</TABLE>";
            ?>        </CENTER></BODY></HTML>

The DB module also includes a DB::isError method to handle errors. Whenever we get a result from a DB module method, we can pass it to the DB::isError method. If that method returns trUE, there was an error, and we can display the appropriate error message with the result object’s getMessage method:

$db = DB::connect('mysql://root:@localhost/produce');
if(DB::isError($db)){
    die($db->getMessage());
}

Now that we can execute SQL statements using the DB module, we have access to most database applicationsall we have to do to select a different type of database server is to change the name of the server type in the connection string.

No Comments

Hello ICE World!

Hello ICE World!I am Matin Rahman ICE-7th Batch.

matinpc1

    

Welcome to ICEIU NETWORK.

Visit the ICE Home Site
Visit the ICE WiKi Site and Contribute for ICE.
Visit the ICE Forum Site and ask and answer questions.

You can also get a 50 MB blog site like me. Goto Blog Home or Sign Up from here. You Can Change your themes and customize your site by logging in and entering to Site Admin.

No Comments