0% found this document useful (0 votes)
40 views9 pages

Modern Web Applications

i

Uploaded by

Subu Sekhar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views9 pages

Modern Web Applications

i

Uploaded by

Subu Sekhar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

modern web applications

Date : 09/11/2023

Submitted By :
Name : SUBHRANSU SEKHAR ROUT

Reg.No : 20BBS0176

COURSE CODE : CBS3014

SLOT : L53+L54

SUBMITTED TO -: SIVAKUMAR V

LAB DA : 04

Config.php

20BBS0176 – VIT VELLORE


<?php
$hostname = "localhost";
$username = "root";
$password = "";
$database = "sekhar";
$connection = mysqli_connect($hostname, $username, $password,
$database);
if (!$connection) {
die("Connection failed: " . mysqli_connect_error());
}

Create.php

<?php include("config.php");

$sql = "CREATE TABLE employee (


id INT AUTO_INCREMENT PRIMARY KEY, username VARCHAR(50) NOT NULL, email
VARCHAR(50) NOT NULL
)";

if (mysqli_query($connection, $sql)) { echo "Table created


successfully";
} else {
echo "Error creating table: " . mysqli_error($connection);
}

mysqli_close($connection);

index.php

<!DOCTYPE html>
<html>

<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>

<body>
<header>
<h1>PHP & MySQL 20BBS0176</h1>
</header>

20BBS0176 – VIT VELLORE


<nav>
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="insert.php">Insert Data</a></li>
<li><a href="update.php">Update Data</a></li>
<li><a href="view.php">View Data</a></li>
<li><a href="delete.php">Delete Data</a></li>
</ul>
</nav>
<main>
<div class="content">
<!-- Page content goes here -->
</div>
</main>
<footer>
<p>&copy; 2023 $EKH@R</p>
</footer>
</body>

</html>

Insert.php

<!DOCTYPE html>

<html>

<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>

20BBS0176 – VIT VELLORE


<body>
<main>
<div class="content">
<h2 style="text-align: center;">Insert Employee Data</h2>
<form method="post">
<label for="id">ID:</label>
<input type="text" name="id" required><br>
<label for="username">Username:</label>
<input type="text" name="username" required><br>
<label for="email">Email:</label>
<input type="email" name="email" required><br>
<input type="submit" value="Insert">
</form>
</div>
</main>
</body>

</html>

<?php include("config.php");

if ($_SERVER["REQUEST_METHOD"] == "POST") {
$id = $_POST["id"];
$username = $_POST["username"];
$email = $_POST["email"];

$sql = "INSERT INTO employee (id,username, email) VALUES


('$id','$username', '$email')";

if (mysqli_query($connection, $sql)) { echo "Data inserted


successfully";
} else {
echo "Error inserting data: " . mysqli_error($connection);
}
}

mysqli_close($connection);
?>

20BBS0176 – VIT VELLORE


Update.php

<?php
include("config.php");
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$id = $_POST["id"];
$newEmail = $_POST["newEmail"];

$sql = "UPDATE employee SET email='$newEmail' WHERE id='$id'";

if (mysqli_query($connection, $sql)) { echo "Data updated


successfully";
} else {
echo "Error updating data: " . mysqli_error($connection);
}
}

mysqli_close($connection);
?>

<!DOCTYPE html>
<html>

<head>
<link rel="stylesheet" type="text/css" href="style.css">

20BBS0176 – VIT VELLORE


</head>

<body>
<main>
<div class="content">
<h2>Update Employee Data</h2>
<form method="post">
<label for="id">User ID:</label>
<input type="text" name="id" required><br>
<label for="newEmail">New Email:</label>
<input type="email" name="newEmail" required><br>
<input type="submit" value="Update">
</form>
</div>
</main>
</body>

</html>

Delete.php

<?php include("config.php");

if ($_SERVER["REQUEST_METHOD"] == "POST") {
$id = $_POST["id"];
$sql = "DELETE FROM employee WHERE id='$id'"; if
(mysqli_query($connection, $sql)) {
echo "Data deleted successfully";
} else {
echo "Error deleting data: " . mysqli_error($connection);

20BBS0176 – VIT VELLORE


}
}

mysqli_close($connection);
?>
<!DOCTYPE html>
<html>

<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>

<body>
<main>
<div class="content">
<h2>Delete Data</h2>
<form method="post">
<label for="id">User ID:</label>
<input type="text" name="id" required><br>
<input type="submit" value="Delete">
</form>
</div>
</main>
</body>

</html>

View.php

<?php include("config.php");

$sql = "SELECT * FROM employee";

20BBS0176 – VIT VELLORE


$result = mysqli_query($connection, $sql);

?>

<!DOCTYPE html>
<html>

<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>

<body>
<main>
<div class="content">
<h2>View Employee Data</h2>
<table>
<tr>
<th>ID</th>
<th>Username</th>
<th>Email</th>
</tr>
<?php
while ($row = mysqli_fetch_assoc($result)) { echo "<tr><td>" .
$row["id"] . "</td><td>" .
$row["username"] . "</td><td>" . $row["email"] . "</td></tr>";
}
?>
</table>
</div>
</main>
</body>

</html>

20BBS0176 – VIT VELLORE


20BBS0176 – VIT VELLORE

You might also like