-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2b54f5f
Showing
7 changed files
with
337 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
-- phpMyAdmin SQL Dump | ||
-- version 4.4.11 | ||
-- http://www.phpmyadmin.net | ||
-- | ||
-- Host: localhost | ||
-- Generation Time: Aug 30, 2015 at 01:22 PM | ||
-- Server version: 5.5.44-0ubuntu0.14.04.1 | ||
-- PHP Version: 5.5.9-1ubuntu4.11 | ||
|
||
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; | ||
SET time_zone = "+00:00"; | ||
|
||
|
||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; | ||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; | ||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; | ||
/*!40101 SET NAMES utf8mb4 */; | ||
|
||
-- | ||
-- Database: `basic phpmyadmin` | ||
-- | ||
|
||
-- -------------------------------------------------------- | ||
|
||
-- | ||
-- Table structure for table `users` | ||
-- | ||
|
||
CREATE TABLE IF NOT EXISTS `users` ( | ||
`id` int(11) NOT NULL, | ||
`fname` varchar(20) NOT NULL, | ||
`lname` varchar(20) NOT NULL, | ||
`marks` int(10) DEFAULT '0', | ||
`last_updated_ux` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP | ||
) ENGINE=InnoDB DEFAULT CHARSET=latin1; | ||
|
||
-- | ||
-- Indexes for dumped tables | ||
-- | ||
|
||
-- | ||
-- Indexes for table `users` | ||
-- | ||
ALTER TABLE `users` | ||
ADD PRIMARY KEY (`id`); | ||
|
||
-- | ||
-- AUTO_INCREMENT for dumped tables | ||
-- | ||
|
||
-- | ||
-- AUTO_INCREMENT for table `users` | ||
-- | ||
ALTER TABLE `users` | ||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT; | ||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; | ||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; | ||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
|
||
if(isset($_POST["submit"])){ | ||
$id = $_POST["id"]; | ||
|
||
if($id != ""){ | ||
include "inc.database.php"; | ||
$connectionStatus = connect_db(); | ||
$status = delete_data($connectionStatus, $id); | ||
if($status){ | ||
header("Location: index.php?id=success&v=Deletion was successfull"); | ||
}else{ | ||
header("Location: index.php?id=success&v=Error: Incorrect User Id"); | ||
} | ||
} | ||
else {header("location:index.php?id=error&v=Error: All fields mandatory"); | ||
} | ||
|
||
|
||
} | ||
else{ | ||
header("location:index.php"); | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
function connect_db(){ | ||
$connectionStatus = mysqli_connect("localhost", "root", "696163", "basic phpmyadmin"); | ||
if(!$connectionStatus){ | ||
echo "Error connecting database"; | ||
die; | ||
} | ||
return $connectionStatus; | ||
} | ||
|
||
function select_data($connectionStatus){ | ||
$query = "SELECT * FROM `users`"; | ||
$result = mysqli_query($connectionStatus, $query); | ||
if(mysqli_num_rows($result) > 0){ | ||
mysqli_close($connectionStatus); | ||
return $result; | ||
} | ||
return false; | ||
} | ||
|
||
function insert_data($connectionStatus, $fname, $lname, $marks){ | ||
$query = "INSERT INTO `users`(`fname`,`lname`,`marks`) VALUES ('$fname','$lname','$marks')"; | ||
$result = mysqli_query($connectionStatus, $query); | ||
|
||
|
||
if(mysqli_affected_rows($connectionStatus)){ | ||
return true; | ||
} | ||
return false; | ||
|
||
} | ||
|
||
function update_data($connectionStatus, $id, $choice, $newValue, $marks){ | ||
if ($choice == "marks"){ | ||
$query = "UPDATE `users` SET `marks`='$newValue' WHERE `id`=$id"; | ||
} else if($choice == "fname"){ | ||
$query = "UPDATE `users` SET `fname`='$newValue' WHERE `id`=$id"; | ||
} else if($choice == "lname"){ | ||
$query = "UPDATE `users` SET `lname`='$newValue' WHERE `id`=$id"; | ||
} | ||
|
||
$result = mysqli_query($connectionStatus, $query); | ||
|
||
if(mysqli_affected_rows($connectionStatus)){ | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
function delete_data($connectionStatus, $id){ | ||
$query = "DELETE FROM `users` WHERE `id` = $id"; | ||
$result = mysqli_query($connectionStatus, $query); | ||
|
||
if(mysqli_affected_rows($connectionStatus)){ | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
require_once "inc.database.php"; | ||
$connectionStatus = connect_db(); | ||
?> | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Basic MySQL Admin Panel</title> | ||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> | ||
<link rel="stylesheet" type="text/css" href="public/css/style.css"> | ||
</head> | ||
<body> | ||
<div class="col-md-12" id="wrapper"> | ||
<div class="row"> | ||
<div class="col-md-2"> | ||
<div class="form-wrapper"> | ||
<form method="post" action="insert.php"> | ||
<input class="form-control" name="fname" placeholder="First name"> | ||
<input class="form-control" name="lname" placeholder="Last name"> | ||
<input class="form-control" name="marks" placeholder="Marks"> | ||
<button type="submit" class="btn btn-success" name="submit">INSERT</button> | ||
</form> | ||
</div> | ||
<div class="form-wrapper"> | ||
<form method="post" action="update.php"> | ||
<select class="form-control" name="choice"> | ||
<option value="">Choose field</option> | ||
<option value="fname">First Name</option> | ||
<option value="lname">Last Name</option> | ||
<option value="marks">Marks</option> | ||
</select> | ||
<input class="form-control" name="id" placeholder="User id"> | ||
<input class="form-control" name="update-value" placeholder="New value"> | ||
<button type="submit" class="btn btn-warning" name="submit">UPDATE</button> | ||
</form> | ||
</div> | ||
<div class="form-wrapper"> | ||
<form method="post" action="delete.php"> | ||
<input class="form-control" name="id" placeholder="id"> | ||
<button type="submit" class="btn btn-danger" name="submit">DELETE</button> | ||
</form> | ||
</div> | ||
</div> | ||
<div class="col-md-10" id="right-section"> | ||
<h1>STUDENT's DATA SHEET</h1> | ||
<table class="table table-hover table-condensed"> | ||
<tr> | ||
<th>ID</th> | ||
<th>First Name</th> | ||
<th>Last Name</th> | ||
<th>Marks</th> | ||
<th>Result</th> | ||
</tr> | ||
|
||
<?php | ||
$PASSING_MARKS = 40; //passing marks | ||
$query_result = select_data($connectionStatus); | ||
while($query_row = mysqli_fetch_assoc($query_result)){ | ||
$marks_scored = $query_row["marks"]; | ||
|
||
echo "<tr> | ||
<td>" . $query_row["id"] . "</td> | ||
<td>" . $query_row["fname"] . "</td> | ||
<td>" . $query_row["lname"] . "</td> | ||
<td>" . $marks_scored . "</td> | ||
<td>"; | ||
echo ($PASSING_MARKS < $marks_scored) ? '<span id="success">PASS</span>' : '<span id="error">FAIL</span>'; | ||
echo "</td> | ||
</tr>"; | ||
} | ||
?> | ||
</table> | ||
<div id="message"> | ||
<?php | ||
if(isset($_GET["id"])){ | ||
echo "<div id='".$_GET["id"]."'>".$_GET["v"]."</div>"; | ||
} | ||
?> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> | ||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
|
||
if(isset($_POST["submit"])){ | ||
|
||
$fname = $_POST["fname"]; | ||
$lname = $_POST["lname"]; | ||
$marks = $_POST["marks"]; | ||
|
||
if($fname != "" AND $lname != "" AND $marks != ""){ | ||
include "inc.database.php"; | ||
$connectionStatus = connect_db(); | ||
$status = insert_data($connectionStatus, $fname, $lname, $marks); | ||
if($status){ | ||
header("Location: index.php?id=success&v=Insertion was successfull"); | ||
}else{ | ||
header("Location: index.php?id=success&v=Error: Insertion Error"); | ||
} | ||
} | ||
else {header("location:index.php?id=error&v=Error: All fields mandatory"); | ||
} | ||
|
||
|
||
} | ||
else{ | ||
header("location:index.php"); | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
@import url(http://fonts.googleapis.com/css?family=Roboto:400,900); | ||
body{ | ||
font-family: 'Roboto', sans-serif; | ||
} | ||
#wrapper{ | ||
padding: 10px; | ||
overflow: hidden; | ||
|
||
} | ||
|
||
.form-wrapper{ | ||
border: 1px solid #DDDDDD; | ||
padding: 5px; | ||
margin-bottom: 5px; | ||
text-align: center; | ||
} | ||
|
||
.form-wrapper form{ | ||
margin-bottom: 0 | ||
} | ||
|
||
.form-wrapper form button{ | ||
margin-top: 10px; | ||
} | ||
|
||
#message{ | ||
padding-top:20px; | ||
font-weight:10px; | ||
} | ||
h1{ | ||
text-align:center; | ||
} | ||
#success, #error{ | ||
text-align: center; | ||
margin-top: 40px; | ||
font-weight: bold; | ||
} | ||
|
||
#success{ | ||
color:green; | ||
} | ||
|
||
#error{ | ||
color:red; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
|
||
if(isset($_POST["submit"])){ | ||
$id = $_POST["id"]; | ||
$choice = $_POST["choice"]; | ||
$newValue = $_POST["update-value"]; | ||
|
||
|
||
if($id != "" AND $choice != "" AND $newValue != ""){ | ||
include "inc.database.php"; | ||
$connectionStatus = connect_db(); | ||
$status = update_data($connectionStatus, $id, $choice, $newValue); | ||
if($status){ | ||
header("Location: index.php?id=success&v=updation was successfull"); | ||
}else{ | ||
header("Location: index.php?id=success&v=Error: Incorrect User Id"); | ||
} | ||
} | ||
else {header("location:index.php?id=error&v=Error: All fields mandatory"); | ||
} | ||
|
||
|
||
} | ||
else{ | ||
header("location:index.php"); | ||
} | ||
|
||
?> |