DATABASEPROG
DATABASEPROG
SOURCE CODE:
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>
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
{
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>
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
5. INSERT FIELD NAME AND THEIR TYPE, INCREASE FIELD BY ADDING – SAVE
12
OUTPUT SCREEN
DATABASE CONNECTION
14
MENU
INSERTION FORM
15
REPORT SCREEN
DELETION FORM:
UPDATION FORM