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

Project Final

The document contains code for a web form that allows users to perform various database operations like create table, insert/update/delete records, and display all records. It first defines the form layout and styles. It then contains PHP code that connects to a MySQL database based on the user's selections, performs the corresponding SQL queries, and displays the results. Appropriate validation is also done, like checking phone number format.

Uploaded by

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

Project Final

The document contains code for a web form that allows users to perform various database operations like create table, insert/update/delete records, and display all records. It first defines the form layout and styles. It then contains PHP code that connects to a MySQL database based on the user's selections, performs the corresponding SQL queries, and displays the results. Appropriate validation is also done, like checking phone number format.

Uploaded by

Prasanth. S
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Newhtml.

html:

<!DOCTYPE html>

<html>

<head>

<title>Database Operations</title>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<style>

body {

font-family: Arial, sans-serif;

background-image: url('https://png.pngtree.com/background/20210709/original/pngtree-
technology-sense-smart-lock-advertising-background-picture-image_960160.jpg');

background-size: cover;

background-position: center;

form {

max-width: 400px;

margin: 0 auto;

padding: 40px;

border-radius: 8px;

box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);

background-image: url("https://media.istockphoto.com/id/1223914421/vector/abstract-blue-
wave-background.jpg?s=612x612&w=0&k=20&c=W8IAWjODYdStfbZXxqdG-
ovDG2rWjRehnlrQCw1eDn0=");

h1 {

text-align: center;

margin-bottom: 30px;
color: #333333;

max-width: 400px;

margin: 0 auto;

padding: 40px;

border-radius: 8px;

box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);

background-image:
url("https://st4.depositphotos.com/20524830/25837/i/600/depositphotos_258375388-stock-photo-
abstract-blue-nature-soft-blurred.jpg");

label {

display: block;

margin-bottom: 10px;

color: #555555;

.container{

border: 1px solid #dddddd;

border-radius: 4px;

box-sizing: border-box;

margin-left: 30%;

margin-right: 30%;

padding:5px;

max-width: available;

background-image:
url("https://i.pinimg.com/originals/5a/65/37/5a653708fd9248867cb90a09919a40e8.jpg");

input[type="text"],

input[type="number"],

input[type="email"],

select {
width: 100%;

padding: 12px;

margin-bottom: 20px;

border: 1px solid #dddddd;

border-radius: 4px;

box-sizing: border-box;

font-size: 16px;

background-color: #f9f9f9;

input[type="submit"] {

background-color: #4CAF50;

color: #ffffff;

padding: 14px 20px;

border: none;

border-radius: 4px;

cursor: pointer;

font-size: 16px;

transition: background-color 0.3s ease;

input[type="submit"]:hover {

background-color: #45a049;

</style>

</head>

<body>

<div class="container">

<h1>DataBase Operations</h1>

<br>

<form method="post" action="newEmptyPHP.php">


<label for="dbname">Database Name:</label>

<input type="text" name="dbname" required placeholder="Enter Database Name">

<label for="tname">Table Name:</label>

<input type="text" name="tname" required placeholder="Enter Table Name">

<label for="choice">Enter Your Choice:</label>

<select name="choice">

<option>Create table</option>

<option>Insert record in table</option>

<option>Update record in table</option>

<option>Delete record in table</option>

<option>Display all records</option>

</select>

<label for="reg">Register Number:</label>

<input type="number" name="reg" placeholder="Enter Your Register Number">

<label for="name">Name:</label>

<input type="text" name="name" placeholder="Enter your Name">

<label for="dept">Department:</label>

<select name="dept">

<option>IT</option>

<option>CT</option>

<option>AUTO</option>

<option>RPT</option>

<option>PT</option>

<option>ECE</option>

<option>E&I</option>

<option>AERO</option>
</select>

<label for="phnum">Mobile Number:</label>

<input type="number" name="phnum" placeholder="Enter Your Phone Number">

<label for="email">Email:</label>

<input type="email" name="email" placeholder="Enter your Email">

<input type="submit" value="Submit">

</form>

</div>

</body>

</html>

newEmptyPHP.php:

<!DOCTYPE html>

<html>

<head>

<title>Database Operations</title>

<style>

body {

font-family: Arial, sans-serif;

margin: 0;

padding: 20px;

background-image: url('https://png.pngtree.com/background/20210709/original/pngtree-
technology-sense-smart-lock-advertising-background-picture-image_960160.jpg');

background-size: 150%;

background-position: center;

}
.container {

max-width: 500px;

margin: 0 auto;

padding: 20px;

border-radius: 5px;

box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);

background-image:
url("https://st4.depositphotos.com/20524830/25837/i/600/depositphotos_258375388-stock-photo-
abstract-blue-nature-soft-blurred.jpg");

.result {

margin-top: 20px;

background-color: #f9f9f9;

padding: 10px;

border-radius: 3px;

border: 1px solid #ccc;

background-image: url("https://media.istockphoto.com/id/1223914421/vector/abstract-blue-
wave-background.jpg?s=612x612&w=0&k=20&c=W8IAWjODYdStfbZXxqdG-
ovDG2rWjRehnlrQCw1eDn0=");

.error {

color: red;

padding: 10px;

border-radius: 3px;

border: 1px solid #ccc;

background-image: url("https://media.istockphoto.com/id/1223914421/vector/abstract-blue-
wave-background.jpg?s=612x612&w=0&k=20&c=W8IAWjODYdStfbZXxqdG-
ovDG2rWjRehnlrQCw1eDn0=");

</style>

</head>
<body>

<div class="container">

<?php

extract($_POST);

$dbname = $dbname;

$tname = $tname;

$choice = $choice;

$reg = $reg;

$name = $name;

$dept = $dept;

$phnum = $phnum;

$email = $email;

$host = "localhost";

$user = "root";

if($phnum!=""){

if(strlen($phnum)!=10){

echo"<div class='result'>Phone Number must be only 10 digits.</div>";

exit;

$conn = new mysqli($host, $user, "", $dbname);

if ($choice == "Create table") {

$sql = "CREATE TABLE $tname(Register_Number INT(10), Name VARCHAR(30), Department


VARCHAR(30), Phone_Number INT(10), Email VARCHAR(30))";

if ($conn->query($sql) === TRUE) {

echo '<div class="result">Table <strong>' . $tname . '</strong> created successfully</div>';

} else {

echo '<div class="error">Error creating table: ' . $conn->error . '</div>';

$conn->close();
} elseif ($choice == "Insert record in table") {

$sql = "INSERT INTO $tname(Register_Number, Name, Department, Phone_Number, Email)


VALUES($reg, '$name', '$dept', $phnum, '$email')";

if ($conn->query($sql) === TRUE) {

echo '<div class="result">New record created successfully</div>';

} else {

echo '<div class="error">Error: ' . $sql . '<br>' . $conn->error . '</div>';

$conn->close();

} elseif ($choice == "Update record in table") {

$sql = "UPDATE $tname SET Name='$name', Department='$dept', Phone_Number=$phnum,


Email='$email' WHERE Register_Number=$reg";

if ($conn->query($sql) === TRUE) {

echo '<div class="result">Record updated successfully</div>';

} else {

echo '<div class="error">Error updating record: ' . $conn->error . '</div>';

$conn->close();

} elseif ($choice == "Display all records") {

$sql = "SELECT * FROM $tname";

$result = $conn->query($sql);

if ($result->num_rows > 0) {

echo "<h2>Table Records </h2>";

while ($row = $result->fetch_assoc()) {

echo '<div class="result">';

echo 'Register Number: ' . $row['Register_Number'] . '<br>';

echo 'Name: ' . $row['Name'] . '<br>';

echo 'Department: ' . $row['Department'] . '<br>';

echo 'Phone Number: ' . $row['Phone_Number'] . '<br>';

echo 'Email: ' . $row['Email'] . '<br>';

echo '</div>';

}
} else {

echo '<div class="result">Table is empty</div>';

$conn->close();

} elseif ($choice == "Delete record in table") {

$sql = "DELETE FROM $tname WHERE Register_Number=$reg";

if ($conn->query($sql) === TRUE) {

echo '<div class="result">Record deleted successfully</div>';

} else {

echo '<div class="error">Error deleting record: ' . $conn->error . '</div>';

$conn->close();

?>

</div>

</body>

</html>
Table Creation :
Validation of Phone Number :
If "Insert record in Table" option was selected :
If "Update record in Table" option was selected :
If "Delete record in Table " option was selected :
If "Display all records " option was selected :

You might also like