PHP Project

Address Book System:
A minor project in PHP.
Databsae: PHPMyAdmin, Wamp Server

Code for Insert data into Database:-

<html>
<body>
<form>
<table align="center">
<tr><td>Name:</td><td><input type="text" name="name"></td></tr>
<tr><td>Mobile:</td><td><input type="text" name="mobile"></td></tr>
<tr><td>Gender:</td><td><input type="radio" value="Female" name="gender">Female<input type="radio" value="Male" name="gender">Male</td></tr>
<tr><td>Colony:</td><td><input type="text" name="colony"></td></tr>
<tr><td>City:</td><td><input type="text" name="city"></td></tr>
<tr><td>Pin code:</td><td><input type="text" name="pincode"></td></tr>
<tr><td><input type="submit" value="Save" name="save"></td></tr>
</table>
</form>
</body>
</html>

<?php
if(isset($_REQUEST['save']))
{
$name = $_REQUEST['name'];
$mobile = $_REQUEST['mobile'];
$gender = $_REQUEST['gender'];
$colony = $_REQUEST['colony'];
$city = $_REQUEST['city'];
$pincode = $_REQUEST['pincode'];

$connection = Mysqli_connect("localhost","root","","addressbookdb");
$query = "insert into addressbook values ('$name', '$mobile', '$gender', '$colony', '$city', '$pincode')";
Mysqli_query($connection, $query);

}
?>



Code for Select data from Database:-


<html>
<body>
<?php
$connection = Mysqli_connect("localhost","root","","addressbookdb");
$query = "select * from addressbook";

$res = Mysqli_query($connection, $query);
echo "<table border='2'>";
while ($show = Mysqli_fetch_array($res))
{

echo "<tr>";
echo "<td> $show[0] </td>";
echo "<td>$show[1] </td>";
echo "<td>$show[2]</td>";
echo "<td>$show[3]</td>";
echo "<td>$show[4]</td>";
echo "<td>$show[5]</td>";
echo "<td><a href='delete1.php?mobile=$show[1]'><input type='button' value='Delete'></a></td>";
echo "<td><a href='updat.php?Mobile=$show[1]'><input type='button' value='Update'></a></td>";
echo "</tr>";

}
echo "</table>";
?>
</body>
</html>


Code for Delete data from Database:-

<html>
<body>
</body>
</html>

<?php
$mob = $_REQUEST['mobile'];
$connection = mysqli_connect("localhost","root","","addressbookdb");
$query = "delete from addressbook where mobile = '$mob'";
mysqli_query($connection ,$query);
?>



Code for Update data into Database:-

<?php

$mob = $_REQUEST['Mobile'];
$connection = mysqli_connect("localhost","root","","addressbookdb");
$query1 = "select * from addressbook where Mobile = '$mob'";
$k = mysqli_query($connection ,$query1);
$v = mysqli_fetch_array($k);

?>
<form>
<input type="text" value="<?php echo $v[0] ?>" name="name">
<input type="text" value="<?php echo $v[1] ?>" name="mobile">
<input type="text" value="<?php echo $v[2] ?>" name="gender">
<input type="text" value="<?php echo $v[3] ?>" name="colony">
<input type="text" value="<?php echo $v[4] ?>" name="city">
<input type="text" value="<?php echo $v[5] ?>" name="pincode">
<input type="submit" name="updt">
</form>

<?php
if(isset($_REQUEST['updt']))
{
$name=$_REQUEST['name'];
$mobile = $_REQUEST['mobile'];
$gender = $_REQUEST['gender'];
$colony = $_REQUEST['colony'];
$city = $_REQUEST['city'];
$pincode = $_REQUEST['pincode'];
$query2 = "UPDATE `addressbook` SET `Aname`='$name',`Gender`='$gender',`Colony`='$colony',`City`='$city',`Pincode`='$pincode' WHERE Mobile='$mobile'";
$m = mysqli_query($connection ,$query2);

if($m)
{
echo "<script>alert('Updated successfully')</script>";
echo "<script>window.location='select.php'</script>";
}
else
{
echo "<script>alert('Not updated')</script>";
echo "<script>window.location='select.php'</script>";
}
}
?>


LEAVE A REPLY










Related topics

Please use contact page in this website if you find anything incorrect or you want to share more information about the topic discussed above.