0% found this document useful (0 votes)
24 views

DATABASEPROG

The document describes creating a database and table to store telephone directory information. It includes code to connect to the database, design forms for insertion, deletion, updating, and reporting of records, and code examples for each database operation.

Uploaded by

vijay20071204
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

DATABASEPROG

The document describes creating a database and table to store telephone directory information. It includes code to connect to the database, design forms for insertion, deletion, updating, and reporting of records, and code examples for each database operation.

Uploaded by

vijay20071204
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

1

TELEPHONE DIRECTORY INFORMATION


AIM:
Create a database and table – perform the database management (Insertion, Deletion,
Updation) using SQL query.

SOURCE CODE:

1. CONNECTING TO DATABASE – conn.php


<html>
<center><h1>CONNECTING TO DATABASE</h1></center>
<body>
<?php
$host='localhost';
$user='root';
$pass='';
$db='teldb';
$con=mysql_connect($host,$user,$pass);
echo'<br/>';
echo'<br/>';
if(!$con)
{
echo'NOT CONNECTED';
}
else
{
if(!mysql_select_db($db,$con))
{
echo "DATABASE NOT FOUND";
}
2

else
{
echo ("DATABASE ".$db." IS CONNECTED"),"<br>";
}
}
echo'<br/>';
echo'<br/>';
?>
<form method="post" action="form.php">
<input type="submit" name="submit" value="MENU"/>
<form/>
</body>
</html>

2. FORM DESIGN – form.php


<html>
<center><h1>MENU</h1></center>
<h2>1.INSERT</h2>
<h2>2.REPORT</h2>
<h2>3.DELETE</h2>
<h2>4.UPDATE</h2>
<form method ="post" action="menu.php">
<input type="submit" value="SUBMIT" name="submit"></input>
<input type="text" name="ch"></input>
</form>
</body>
</html>
3

3. MENU – menu.php
<html>
<body>
<?php
switch($_POST['ch'])
{
case 1:
include('insert1.php');
break;
case 2:
include('view.php');
break;
case 3:
include('delete1.php');
break;
case 4:
include('update1.php');
break;

}
?>
</body>
</html>
4. INSERTION FORM – insert1.php
<html>
<body>
<form method="post" action="insert2.php">
<center><h1>INSERT NEW RECORD</h1></center>
NAME :
4

<input type="text" name="name"/><br/><br/>


ADDRESS :
<input type="text" name="addr"/><br/><br/>
PHONE NUMBER :
<input type="text" name="phno"/><br/><br/>
<input type="submit" /><br/><br/>
</form>
</body>
</html>
5. INSERTING A RECORD – insert2.php
<html>
<body>
<?php
$host='localhost';
$user='root';
$pass='';
$db='teldb';
$name=$_POST['name'];
$addr=$_POST['addr'];
$phno=$_POST['phno'];
$con=mysql_connect($host,$user,$pass,$db);
if(!$con)
{
echo'NOT CONNECTED';
exit;
}
mysql_select_db($db,$con)or die('COULD NOT SELECT DATABASE');
$sql="INSERT INTO teldb (name,addr,phno) VALUES ('$name','$addr','$phno')";
if(!mysql_query($sql,$con))
5

{
die ('error:'.mysql_error());
}
else
{
echo"NEW RECORD ADDED";
}
?>
<form method="post" action="form.php">
<input type="submit" name="submit" value="MENU"/>
<form/>
</body>
</html>
6. DELETION FORM – delete1.php
<html>
<body>
<form method="post" action="delete2.php">
ENTER NAME TO DELETE :
<input type="text" size="20" name="name"/><br/>
<input type="submit" name="submit" value="DELETE"/>
<form/>
</body>
</html>
7. DELETING A RECORD – delete2.php
<html>
<body>
<?php
$host='localhost';
$user='root';
6

$pass='';
$db='teldb';
$name=$_POST['name'];
$con=mysql_connect($host,$user,$pass);
if(!$con)
{
echo'NOT CONNECTED';
}
else
{
if(!mysql_select_db($db,$con))
{
echo "DATABASE NOT FOUND";
}
else
{
echo ("DATABASE ".$db." IS CONNECTED"),"<br>";
}
}
mysql_select_db($db,$con)or die('COULDNOT SELECT DATABASE');
$sql="DELETE from teldb WHERE (name='$name')";
if(!mysql_query($sql,$con))
{
die ('error:'.mysql_error());
}
?>
<form method="post" action="form.php">
<input type="submit" name="submit" value="MENU"/>
<form/>
7

</body>
</html>
8. UPDATION FORM – update1.php
<html>
<body>
<form method="post" action="update2.php">
<center><h1>MODIFY THE RECORD</h1></center>
EXISTING NAME :
<input type="text" name="name"/><br/>
NEW NAME :
<input type="text" name="nname"/><br/><br/>
<input type="submit" name="update" value="UPDATE"/><br/>
</form>
</body>
</html>

9. UPDATING A RECORD – update2.php


<html>
<body>
<?php
$host='localhost';
$user='root';
$pass='';
$db='teldb';
$nname=$_POST['nname'];
$name=$_POST['name'];
$con=mysql_connect($host,$user,$pass,$db);
if(!$con)
{
8

echo'NOT CONNECTED';
exit;
}
mysql_select_db($db,$con) or die('COULDNOT SELECT DATABASE');
$sql="UPDATE teldb SET name='$nname' WHERE (name='$name')";
if(!mysql_query($sql,$con))
{
die ('error:'.mysql_error());
}
?>
<form method="post" action="form.php">
<input type="submit" name="submit" value="MENU"/>
<form/>
</body>
</html>
10. REPORT FORM – view.php
<html>
<body>
<center><h1>CUSTOMER INFORMATION</h1><center>
<?php
include('conn.php');
$result=mysql_query('select * from teldb');
$nr =mysql_num_rows($result);
echo'NUMBER OF ROWS = '.$nr;
echo'<table border=1 width=60%>';
echo'<tr>';
echo'<td width=20%>name</td>';
echo'<td width=20%>addr</td>';
echo'<td width=20%>phno</td>';
9

echo'</tr>';
echo'</table>';
if($nr>0)
while($row=mysql_fetch_array($result))
{
$name=$row['name'];
$addr=$row['addr'];
$phno=$row['phno'];
echo'<table border=1 width=60%>';
echo'<tr>';
echo'<td width=20%>'.$name.'</td>';
echo'<td width=20%>'.$addr.'</td>';
echo'<td width=20%>'.$phno.'</td>';
echo'</tr>';
echo'</table>';
}
?>
<form method="post" action="form.php">
<input type="submit" name="submit" value="MENU"/>
<form/>
</body>
</html>
10

PROCEDURE TO CONNECT THE DATABSE IN WAMP SERVER:


1. OPEN WAMP SERVER
2. GO TO PhpMyAdmin

3. CREATE NEW DATABASE


11

4. CREATE NEW TABLE AND SELECT NO.OF.FIELDS - GO

5. INSERT FIELD NAME AND THEIR TYPE, INCREASE FIELD BY ADDING – SAVE
12

6. GOTO WAMP SERVER AND SELECT LOCAL HOST

7. RUN PROGRAM ONE BY ONE


• Conn.php
• Form.php
• Insert
• Report
• Update
• Delete …
13

OUTPUT SCREEN

DATABASE CONNECTION
14

MENU

INSERTION FORM
15

REPORT SCREEN

DELETION FORM:

UPDATION FORM

You might also like