Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebStacks Test, Database Operations (Hemanth S) #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Screenshot_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshot_2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshot_3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshot_4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bright.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions connect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
$conn = mysqli_connect("localhost","root","","details");
if (!$conn)
{
die("Connection failed: " . mysqli_connect_error());
}
?>
18 changes: 18 additions & 0 deletions delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
include 'connect.php';
$email=$_POST['email'];
if(empty($email))
echo "Please Give a Valid Name";
else
$sql="DELETE FROM details WHERE email = '$email'";

if(mysqli_query($conn,$sql))
echo "Row deleted Successfully<br>";
else
echo "Error deleting Row <br>" . mysqli_error($conn);

echo "<br>Click below to go back";
echo "<br><a href=\"index.html\">Home</a>";

mysqli_close($conn);
?>
106 changes: 106 additions & 0 deletions detailsstyle.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
body
{
background-image: url("bright.jpg");
margin: 0px;
}

input[type=text30]
{
width: 300px;
padding: 8px 20px;
border-radius: 5px;
margin-top: 16px;
border: 1px solid rgb(189,199,216);
font-size: 20px;
}

.custrow:after {
content: "";
display: table;
clear: both;
margin: 0px;
}

.logbutton
{
background-color: yellow;
color: black;
border: 2px solid rgb(154,172,26);
border-radius: 6px;
text-align: center;
font-size: 18px;
padding: 8px 20px;
margin-top: 16px;
margin-right: 10px;
transition-duration: 0.3s;
cursor: pointer;
}

.logbutton:hover
{
background-color: rgb(251,190,32);
color: black;
}

.center {
display: block;
margin-left: auto;
margin-right: auto;
}

.thickborder
{
border: 2px solid rgb(56,56,56);
}

.tdroll
{
width: 10%;
}

.tdname
{
width: 20%;
}

.logbuttonbig
{
background-color: yellow;
color: black;
border: 2px solid rgb(154,172,26);
border-radius: 6px;
text-align: center;
font-size: 24px;
padding: 12px 30px;
margin-top: 16px;
margin-right: 45px;
transition-duration: 0.3s;
cursor: pointer;
margin-left: auto;
margin-right: auto;
}

.logbuttonbig:hover
{
background-color: rgb(251,190,32);
color: black;
}

input[type=text60]
{
width: 100%;
padding: 8px 20px;
border-radius: 5px;
margin: 4px;
border: 1px solid rgb(189,199,216);
font-size: 20px;
text-align: center;
}

.centerback
{
margin-top: 30px;
border-radius: 15px;
background-color: rgba(255,255,255,0.3);
padding-bottom: 50px;
}
72 changes: 72 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<html>
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<link rel="stylesheet" type="text/css" href="detailsstyle.css">

<script type="text/javascript">
function showUser(str) {
if (str.length == 0) {
document.getElementById("SelectTxt").innerHTML = "";
return;
} else {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("SelectTxt").innerHTML = this.responseText;
}
};
xmlhttp.open("GET", "select.php?q=" + str, true);
xmlhttp.send();
}
}
</script>
</head>

<body style="background-image: url(bright.jpg);">
<div class="container centerback">
<br>
<h1 align="center">Details Database Operations</h1>
<br>
<h4 align = "center">Choose any of the Operations Below</h4>
<br>
<button class = "logbuttonbig center" data-toggle="collapse" href="#collapseInsert">Insert</button>
<div class="collapse" id="collapseInsert" style="margin-top: 10px; border-radius: 10px;">
<div class="card card-body">
<form action = "insert.php" method = "POST">
<input type="text60" placeholder="Name" class="center" id="name" name="name">
<input type="text60" placeholder="Phone" class="center" id="phone" name="phone">
<input type="text60" placeholder="E-Mail" class="center" id="email" name="email">
<input type="submit" class="logbutton center" value="Submit">
</form>
</div>
</div>

<button class = "logbuttonbig center" data-toggle="collapse" href="#collapseSelect">Select</button>
<div class="collapse" id="collapseSelect" style="margin-top: 10px; border-radius: 10px;">
<div class="card card-body">
<h5>Enter Name to display specific person details, type ALL to display all details.</h5>
<form action = "select.php" method = "POST">
<input type="text60" placeholder="Name" class="center" id="name" name="name" onkeyup="showUser(this.value)">
<div id="SelectTxt"></div>
</form>
</div>

</div>

<button class = "logbuttonbig center" data-toggle="collapse" href="#collapseDelete">Delete</button>
<div class="collapse" id="collapseDelete" style="margin-top: 10px; border-radius: 10px;">
<div class="card card-body">
<h5>Enter Name to delete specific person record.</h5>
<form action = "delete.php" method = "POST">
<input type="text60" placeholder="E-Mail" class="center" id="email" name="email">
<input type="submit" class="logbutton center" value="Submit">
</form>
</div>
</div>

</div>
</body>
</html>
23 changes: 23 additions & 0 deletions insert.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
include 'connect.php';

$conn = mysqli_connect("localhost","root","","details");
if (!$conn)
{
die("Connection failed: " . mysqli_connect_error());
}

$name = $_POST['name'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$sql = "INSERT INTO details VALUES('$name','$phone','$email')";
if(mysqli_query($conn,$sql))
echo "Values inserted Successfully<br>";
else
echo "Error inserting Values <br>" . mysqli_error($conn);

echo "<br>Click below to go back";
echo "<br><a href=\"index.html\">Home</a>";

mysqli_close($conn);
?>
52 changes: 52 additions & 0 deletions select.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@


<html>
<head>
<link rel="stylesheet" type="text/css" href="detailsstyle.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<title>DetailsDB</title>
</head>

<body>
<div class = "container">
<table class="table" style="margin-top: 30px;">
<tr class="table-light">
<th class=tdroll>Sl No.</th>
<th class=tdname>Name</th>
<th class=tdname>Phone</th>
<th class=tdname>E-Mail</th>
</tr>

<?php
include 'connect.php';
$name=$_REQUEST['q'];
if(strcmp($name,"ALL")===0)
$sql="SELECT * FROM details";
else
$sql="SELECT * FROM details WHERE name = '$name'";

$result = mysqli_query($conn,$sql);
$count = 0;
$arr=array();
while($row=mysqli_fetch_array($result))
{
$arr[]=$row;
$count++;
}
for($i=0;$i<$count;$i++)
{
echo "<tr class=\"table-light\">";
echo "<td class=\"tdroll\">".($i+1)."</td>";
echo "<td class=\"tdname\">".$arr[$i]['name']."</td>";
echo "<td class=\"tdname\">".$arr[$i]['phone']."</td>";
echo "<td class=\"tdname\">".$arr[$i]['email']."</td>";
echo "</tr>";
}
mysqli_close($conn);
?>

</table>
</div>
</body>

</html>