CSE3002 – Internet and Web Programming Solved

$ 29.99
Category:

Description

CSE3002

Lab Assignment 10

ISHAAN OHRI
18BC E0265

Question:
Design a web application using PHP to perform all the Database operations.
Create an address book web application that allows the user to store and retrieve several mailing lists from MySQL database. The address book contains firstname,designation, address1, address2, City, State,emailid. user can add, update and delete all address informationโ€™s in the database. Implement search operation with emailid,when emailed is given it return an HTML page with all the complete address information .
C ode:
index.php

<?php include(‘db_connect.php’); if(isset($_POST[‘submit’])) {
$name = $_POST[‘name’];
$designation = $_POST[‘designation’];
$add1 = $_POST[‘add1’];
$add2 = $_POST[‘add2’];
$city = $_POST[‘city’];
$state = $_POST[‘state’];
$email = $_POST[’email’];
$sql = “INSERT INTO addresses(emailid, name, designation, address1, address2, city, state) VALUES(‘$email’, ‘$name’, ‘$designation’, ‘$add1’, ‘$add2’,
‘$city’, ‘$state’)”;
if(mysqli_query($conn, $sql)) { echo ‘<div class=”success”>
Added Successfully !
</div>’; } else {
echo ‘<div class=”error”>
Error : ‘ . mysqli_error($conn) . ‘
</div>’;
}
}
?>
<?php include ‘header.php’ ?>
<div class=”form-container”>
<div class=”btns”>
<span><a href=”index.php”><button>New</button></a></span>
<span><a href=”update.php”><button class=’disabled’>Update</button></a></span>
<span><a href=”delete.php”><button class=’disabled’>Delete</button></a></span>
<span><a href=”search.php”><button class=’disabled’ >Search</button></a>
</span>
</div>
<form action=”index.php” method=’POST’>
<h2>New Entry</h2>
<div class=”name”>
<input required id=”name” type=”text” name=”name” placeholder=”Name”> </div>
<div class=”designation”>
<input required id=”designation” type=”text” name=”designation” placeh older=”Designation”>
</div>
<div class=”add1″>
<input required id=”add1″ type=”text” name=”add1″ placeholder=”Address1″>
</div>
<div class=”add2″>
<input required id=”add2″ type=”text” name=”add2″ placeholder=”Address2″>
</div>
<div class=”city”>
<input required id=”city” type=”text” name=”city” placeholder=”City”> </div>
<div class=”state”>
<input required id=”state” type=”text” name=”state” placeholder=”State”>
</div>
<div class=”email”>
<input required id=”email” type=”email” name=”email” placeholder=”Email ID”> </div>
<button name=”submit” class=”submit” type=”submit”>Submit</button>
</form>
</div>
</body>
</html>

update.php
<?php include(‘db_connect.php’); if(isset($_POST[‘submit’])) { $name = $_POST[‘name’];
$designation = $_POST[‘designation’];
$add1 = $_POST[‘add1’];
$add2 = $_POST[‘add2’];
$city = $_POST[‘city’];

$state = $_POST[‘state’];
$email = $_POST[’email’];
$sql = “UPDATE addresses
SET emailid = ‘$email’, designation= ‘$designation’, address1= ‘$add1’, address2= ‘$add2’, city= ‘$city’, state= ‘$state’ WHERE name = ‘$name’”; if(mysqli_query($conn, $sql)) { echo ‘<div class=”success”>
Updated Successfully !
</div>’; } else {
echo ‘<div class=”error”>
Error : ‘ . mysqli_error($conn) . ‘
</div>’;
}
}
?>
<?php include ‘header.php’ ?>
<div class=”form-container”>
<div class=”btns”>
<span><a href=”index.php”><button class=”disabled”>New</button></a></spa n>
<span><a href=”update.php”><button >Update</button></a></span>
<span><a href=”delete.php”><button class=”disabled”>Delete</button></a> </span>
<span><a href=”search.php”><button class=’disabled’ >Search</button></a>
</span>
</div>
<form action=”update.php” method=’POST’>
<h2>Update Entry</h2>
<div class=”name”>
<input id=”name” type=”text” name=”name” placeholder=”Name”>
</div>
<div class=”designation”>
<input id=”designation” type=”text” name=”designation” placeholder=”De signation”>
</div>
<div class=”add1″>
<input id=”add1″ type=”text” name=”add1″ placeholder=”Address 1″> </div>
<div class=”add2″>
<input id=”add2″ type=”text” name=”add2″ placeholder=”Address 2″> </div>
<div class=”city”>
<input id=”city” type=”text” name=”city” placeholder=”City”> </div>
<div class=”state”>
<input id=”state” type=”text” name=”state” placeholder=”State”> </div>
<div class=”email”>
<input id=”email” type=”email” name=”email” placeholder=”Email ID”>

</div>
<button name=”submit” class=”submit” type=”submit”>Submit</button>
</form>
</div>
</body>
</html>

delete.php

<?php include(‘db_connect.php’); if(isset($_POST[‘submit’])) {
$name = $_POST[‘name’];
$email = $_POST[’email’];
$sql = “DELETE FROM addresses WHERE name= ‘$name’ and emailid= ‘$email’”
;
if(mysqli_query($conn, $sql)) { echo ‘<div class=”success”>
Deleted Successfully !
</div>’; } else {
echo ‘<div class=”error”>
Error : ‘ . mysqli_error($conn) . ‘
</div>’;
}
}
?>
<?php include ‘header.php’ ?>
<div class=”form-container”>
<div class=”btns”>
<span><a href=”index.php”><button class=”disabled” >New</button></a></sp an>
<span><a href=”update.php”><button class=’disabled’>Update</button></a>< /span>
<span><a href=”delete.php”><button >Delete</button></a></span>
<span><a href=”search.php”><button class=’disabled’ >Search</button></a>
</span>
</div>
<form action=”delete.php” method=’POST’>
<h2>Delete Entry</h2>
<div class=”name”>
<input id=”name” type=”text” name=”name” placeholder=”Name”>
</div>
<div class=”email”>
<input id=”email” type=”email” name=”email” placeholder=”Email ID”> </div>
<button name=”submit” class=”submit” type=”submit”>Submit</button>
</form>
</div>
</body>
</html>

db_connect.php

<?php
// Connect to DB
$conn = mysqli_connect(‘localhost’, ‘shivam’, ‘@1SHIVAManand’, ‘addresses’); if(!$conn){
echo “Connection Error : ” . mysqli_connect_error();
}
?>

search.php

<?php include(‘db_connect.php’);
?>
<?php include ‘header.php’ ?>
<div class=”form-container”>
<div class=”btns”>
<span><a href=”index.php”><button class=”disabled”>New</button></a></spa n>
<span><a href=”update.php”><button class=”disabled” >Update</button></a> </span>
<span><a href=”delete.php”><button class=”disabled”>Delete</button></a> </span>
<span><a href=”search.php”><button >Search</button></a></span> </div>
<form action=”search.php” method=’POST’>
<h2>Search Entry</h2>
<div class=”email”>
<input id=”email” type=”email” name=”email” placeholder=”Email ID”> </div>
<button name=”submit” class=”submit” type=”submit”>Submit</button>
</form>
</div>
<?php
if(isset($_POST[‘submit’])) {
$email = $_POST[’email’];
$sql = “SELECT * from addresses WHERE emailid= ‘$email’”;
$result = mysqli_query($conn, $sql); if($result) {
$address = mysqli_fetch_assoc($result); echo “<table> <tr>
<th>Name</th>
<th>Email ID</th>
<th>Designation</th>
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<style> @import
url(‘https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,
500;0,700;1,900&display=swap’);
* {
font-family: ‘Roboto’, sans-serif; box-sizing: border-box; border-radius:8px;
} body { margin: 0; padding: 0;
background-color:#33FFEB;
}
.header { font-size: 2rem; color: red;
<th>Address 1</th>
<th>Address 2</th>
<th>City</th>
<th>State</th>
</tr>
<tr>
<td>” . $address[‘name’] . “</td>
<td>” . $address[’emailid’] . “</td>
<td>” . $address[‘designation’]. ” </td>
<td>” . $address[‘address1’]. “</td>
<td>” . $address[‘address2’]. “</td>
<td>” . $address[‘city’]. “</td>
<td>” . $address[‘state’]. “</td>
</tr>
</table>”; } else {
echo ‘<div class=”error”>
Error : ‘ . mysqli_error($conn) . ‘
</div>’;
}
}
?>
</body>
</html>

header.php

padding: 10px 20px; text-align: center;
}
.form-container { display: inline-block; position: relative; left: 50%;
transform: translate(-50%); background-color: white; margin-top: 20px; padding: 30px 50px;
} button { border: none; font-size: 1.2rem; background-color: blue; color: white; padding: 10px 40px; cursor: pointer;
}
.disabled {
background-color: #76686c;
} a { color: white;
text-decoration: none;
}
.submit { margin-top: 30px; width: 100%;
} h2 { color: red; text-align: center; font-weight: 200;
} input { background-color: transparent; border: 1px solid black; padding: 10px; margin: 5px 0; width: 100%; font-size: 1.5rem; color: black;
} .error { padding: 5px; text-align: center; background-color: red;
color: white; }
.success { padding: 7px; text-align: center; background-color: orange; color: white;
}
/* Table */ table { border: 1px solid #0000FF; border-collapse: collapse; margin-top: 20px; padding: 0; width: 100%;
table-layout: fixed;
} table caption { font-size: 1.5em; margin: .7em 0 .95em;
} table tr { background-color: #0080ff; border: 2px solid #ddd; padding: .25em;
} table th, table td { padding: .655em; text-align: center;
} table th { font-size: .95em; letter-spacing: .15em; text-transform: uppercase;
}
</style>
<title>SQL Assessment</title>
</head>
<body>
<div class=’header’>
ISHAAN OHRI 18BCE0265
</div>

Output:

Initially all the fields are empty:

Initially the database is empty:

Data is filled in all fields for new entry:

Submit button clicked and data is successfully added to database:

Data entry to database verified from database:

Data is filled in all fields for updating old entry:

Submit button clicked and data is successfully updated in database:

Data update in database verified from database:

Data is filled in the search field:

Submit button clicked and data is fetched database:

Data is filled in the field to delete the entry:

Submit button is clicked and data entry is deleted form database:

Data deletion from database is verified from database:

Reviews

There are no reviews yet.

Be the first to review “CSE3002 – Internet and Web Programming Solved”

Your email address will not be published. Required fields are marked *