Monday, January 18, 2010

Telephone Directory System(PHP/My SQl)

This blog is about a basic Telephone Management System designed by PHP and MySQl with Wamp Server .This Tutorial I think will help the Be gainers.The most interesting feature of this software is that everything ie. insertion,Deletion,Updation and searching everything is carried out in a single page.I am just providing the code.Copy it and paste it in www folder of your WAMP server and then create a database/Table in the MY Sql Section to find out the full functionability of the software.

First the connection page-
I have named it as "connection.php"

$link=mysql_connect('127.0.0.1','root','');
if(!$link)
{
die('Error Connecting to Server. '.mysql_error());
}
$select_db=mysql_select_db('telephone',$link);
if(!$select_db)
{
die('Error Connecting to Database '.mysql_error());
}


// clear the cache
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
$ExpStr = "Expires: " . gmdate("D, d M Y H:i: s ", time() ) . " GMT";
header($ExpStr);
header('Cache-Control: public, no-cache');
?>


Now the main Page.
I have named it as "resultname.php"

include("connection.php");
$searchname = $_REQUEST['searchname'];
if($_REQUEST["ADD"])
{
$id = $_REQUEST['id'];
$name = $_REQUEST['name'];
$mobile1 = $_REQUEST['mobile1'];
$mobile2 = $_REQUEST['mobile2'];
$mobile3 = $_REQUEST['mobile3'];
$lan1 = $_REQUEST['lan1'];
$lan2 = $_REQUEST['lan2'];
$address = $_REQUEST['address'];
$email = $_REQUEST['email'];

mysql_query("insert into record
(name,mobile1,mobile2,mobile3,lan1,lan2,address,email)
values
('$name','$mobile1','$mobile2','$mobile3','$lan1','$lan2','$address','$email')");
if(mysql_affected_rows() > 0)
{
$msg = "Records Inserted Successfully";
}
else
{
$msg = "Error! record not inserted";
}

}
if($_REQUEST['mode']=="add")
{?>









































Insert New Record
Name
Mobile1
Mobile2
Mobile3
LAN 1
LAN 2
Address
Email











}
if($_REQUEST["Update"])
{
$id = $_REQUEST['id'];
$name = $_REQUEST['name'];
$mobile1 = $_REQUEST['mobile1'];
$mobile2 = $_REQUEST['mobile2'];
$mobile3 = $_REQUEST['mobile3'];
$lan1 = $_REQUEST['lan1'];
$lan2 = $_REQUEST['lan2'];
$address = $_REQUEST['address'];
$email = $_REQUEST['email'];

$sql = "UPDATE record SET
name = '$name' , mobile1 = '$mobile1' , mobile2 = '$mobile2' , mobile3 = '$mobile3' , lan1 = '$lan1' , lan2 = '$lan2' , address = '$address' , email = '$email' WHERE id='$id'";
$result = mysql_query($sql);
if(mysql_affected_rows()>0)
{
$msg = "Updation Completed Successfully";
}
else
{
$msg = "Updation failed";
}

}
if($_REQUEST['mode']=="edit")
{

$result = mysql_query("select * from record where id=".$_GET['id']);
$myrow = mysql_fetch_array($result);?>


">








































Update Record
Name ">
Mobile1 ">
Mobile2 ">
Mobile3 ">
LAN 1 ">
LAN 2 ">
Address
Email ">


" onClick="return confirm('Are You Sure ?)">







}
if($_REQUEST['mode']=="delete")
{
mysql_query("delete from record where id=".$_GET['id']);
$msg = "Record Deleted Successfully.";
}

?>





Edit Content










Welcome To the Telephone Directory Management System













Searching By Name

Enter Name or PH. No to Search



























Record
ADD





";}
else
{echo $msg."
";} ?>














$total = mysql_query("SELECT count(*) as cnt FROM record where name like '%$searchname%' or mobile1 like '%$searchname%' or mobile2 like '%$searchname%' or mobile3 like '%$searchname%' or lan1 like '%$searchname%' or lan2 like '%$searchname%'");
$a = mysql_fetch_object($total);
$total_items = $a->cnt;

//echo "Total Number of records in Database: ".$total_items;
$limit= 10;
$page= $_GET['page'];
echo '' . $set_limit . '';
if((!$limit) || (is_numeric($limit) == false)
|| ($limit <> 50))
{
$limit = 10; //default
}

//Set default if: $page is empty, non numerical,
//less than zero, greater than total available

if((!$page) || (is_numeric($page) == false)
|| ($page <> $total_items))
{
$page = 1; //default
}
$total_pages = ceil($total_items / $limit);
$set_limit = ($page * $limit) - $limit;


$sql="SELECT * FROM record where name like '%$searchname%' or mobile1 like '%$searchname%' or mobile2 like '%$searchname%' or mobile3 like '%$searchname%' or lan1 like '%$searchname%' or lan2 like '%$searchname%' order by name LIMIT $set_limit, $limit";
$sql_query=mysql_query($sql);

while($row=mysql_fetch_array($sql_query))
{
?>













}

$prev_page = $page - 1;

if($prev_page >= 1) {
echo("
Prev ");
// echo $prev_page;
}
for($a = 1; $a <= $total_pages; $a++)
{
if($a == $page) {
echo(" $a | "); //no link
}
else {
echo("
$a
| ");
}
}

//Next page: **EDIT THIS LINK PATH**

$next_page = $page + 1;
if($next_page <= $total_pages) {

echo("
Next");
// echo $next_page;
}



?>
Name Mobile1 Mobile2 Mobile3 Lan1 Lan2 Email Address

&name="
onClick="return confirm('Are You Sure you Want to edit: ?')">EDIT
" onClick="return confirm('Are You Sure you Want to delete: ?')">DELETE






Now the MYSQl Portion

first create a database named-"telephone"

Now the table structure.I have named the table as "record"

now copy paste this command

CREATE TABLE IF NOT EXISTS `record` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`mobile1` varchar(15) NOT NULL,
`mobile2` varchar(15) NOT NULL,
`mobile3` varchar(15) NOT NULL,
`lan1` varchar(15) NOT NULL,
`lan2` varchar(15) NOT NULL,
`address` varchar(100) NOT NULL,
`email` varchar(50) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `name` (`name`)
)

I think that will be all.If you find any problem feel free to contact me @
dasgupta.rony@gmail.com

This is basically for the begainers and doesnot cointain any complexity.

Hope to meet you all very soon.



Sunday, December 13, 2009

GK-2009

1.Fadima Azmi is speaker of which country?
2.In which year Yugi Gargin reached space?
3.Who was the first election Commisioner of India?
4.Which among the given Indian State doesnt form border with Myanmar?
5.Who among the given choices was winner of Dada Saheb Phalke Award for life achievement award?
6.Which instrument is used for measuring earth quake?
7.How old is Indus Valley Civilization?
8.Few question on grammer
9.Question on discount & Profit.
10.A coder can thin 100 lines of code in 5 min and can write 100 line of code in 10 min if he takes break after each 10 min how much code can he write in 1 hr?
etc

Paper Question

Paper -A
1.what is similarity between SUPW and work education?
2.What are the problem in executing work education shyllubus?
3.Difference between vocational tanning and work education?
4.why a work education preparation should be made refreshable by the teacher?
5.How can a fannel board created?
6.What are the steps you should take when you take your student to a production plant?
7.How learning to be can be executed by work education?
8.How the pilars of education are executed by work education?

Paper - B
1.Draw a pic of Vegitative propagation of rose plant.
2.How is terracota made?
3.how is salwar made?
4.How can spellings/grammer mistakes can be rectified in computers?
5. How is new table created and old table modified using spreadsheet?
6.What are the uses of computer in school office?
7.Working of Electric Bell
8.Examle of Electric Attraction
9.What is a soapstock?
10.Home uses of jute.
11.How soil can be made fertile.?
12.How foods are preserved?
13.How medicinal plant can be preserved?
14.What is the importance of Urea?
etc