Skip to content
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
50 changes: 24 additions & 26 deletions addDetails.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
<?php
<?php


$con=mysqli_connect("localhost","root","","crudphp");
// checking connection
if(mysqli_connect_errno())
{
echo "Unable to connect to the database : " .mysqli_connect_error();
}

if(isset($_POST['submit']))
{
$firstName=$_POST['firstName'];
$lastName=$_POST['lastName'];
$email=$_POST['email'];

############################
## BY: SÍLVIO SILVA ##
## 02/09/2022 ##
############################

$query="insert into developerdetails(firstName,LastName,email)
values('$firstName','$lastName','$email')";
include "./app/connection.php";
include "./app/helpers.php";

if(mysqli_query($con,$query))
{
echo "<script>alert('Details Inserted')</script>";
echo "<script>location.href='add.html'</script>";
}
if (isset($_POST['submit'])) {
$firstName = filter($_POST['firstName']);
$lastName = filter($_POST['lastName']);
$email = filter($_POST['email'])/* */;

else
{
echo "Unable to insert the details";
}

}

?>
$query = $pdo->prepare("INSERT INTO developerdetails (firstName, LastName, email) VALUES (?, ?, ?)");
$query->bindParam(1, $firstName);
$query->bindParam(2, $lastName);
$query->bindParam(3, $email);

if ($query->execute()) {
echo "<script>alert('Details Inserted')</script>";
echo "<script>location.href='add.html'</script>";
} else {
echo "Unable to insert the details";
}
}
11 changes: 11 additions & 0 deletions app/connection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

$server = "localhost";
$user = "root";
$pass = "";
$dbname = "crudphp";

$pdo = new PDO("mysql:host=$server;dbname=$dbname", $user, $pass, array(
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
));
12 changes: 12 additions & 0 deletions app/helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

############################
## BY: SÍLVIO SILVA ##
## 02/09/2022 ##
############################

function filter($var)
{

return filter_var($var, FILTER_DEFAULT);
}
160 changes: 77 additions & 83 deletions dashboard.php
Original file line number Diff line number Diff line change
@@ -1,106 +1,100 @@
<?php



############################
## BY: SÍLVIO SILVA ##
## 02/09/2022 ##
############################


require "./app/connection.php";

?>
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Dashboard</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/styles.css">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Dashboard</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/styles.css">

<script type="text/javascript">
function logOut()
{
function logOut() {
alert("You have been logged out");
}
</script>
</head>
<body>
<div class="container-fluid">
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<a class="navbar-brand" href="dashboard.php"><img src="img/hero.png" alt="logo"></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarColor01" aria-controls="navbarColor01" aria-expanded="false" aria-label="Toggle navigation" style="">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbarColor01">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
</li>
<li class="nav-item">
<a class="nav-link" href="add.html" >Add</a>
</li>
</ul>
<a class="btn btn-info" href="index.html" onclick="logOut()">Log Out</a>
</nav>
</div>
<div class="container-fluid">
<h1 class="dashboard-title">Developer Details</h1>
</div>
<div class="data">
<table class="table table-hover">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
<th>Operation</th>
</tr>
</thead>

<?php

$con=mysqli_connect("localhost","root","","crudphp");
<body>
<div class="container-fluid">
<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<a class="navbar-brand" href="dashboard.php"><img src="img/hero.png" alt="logo"></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarColor01" aria-controls="navbarColor01" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

//checking the connection
if(mysqli_connect_errno())
{
echo "Unable to connect to the database : " .mysqli_connect_error();
}
<div class="collapse navbar-collapse" id="navbarColor01">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
</li>
<li class="nav-item">
<a class="nav-link" href="add.html">Add</a>
</li>
</ul>
<a class="btn btn-info" href="index.html" onclick="logOut()">Log Out</a>
</nav>
</div>
<div class="container-fluid">
<h1 class="dashboard-title">Developer Details</h1>
</div>
<div class="data">
<table class="table table-hover">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
<th>Operation</th>
</tr>
</thead>

$query="select * from developerdetails";
$run=mysqli_query($con,$query);
while($row=mysqli_fetch_array($run))
{
$id=$row['id'];
$firstName=$row['firstName'];
$lastName=$row['LastName'];
$email=$row['email'];


?>
<?php
$query = $pdo->prepare("SELECT * FROM developerdetails");
$query->execute();
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
?>

<tbody>
<tr>
<td><?php echo $firstName; ?></td>
<td><?php echo $lastName; ?></td>
<td><?php echo $email; ?></td>
<td>
<a href="devdetails.php?devdetails=<?php echo $id;?>" class="badge badge-primary">Read</a>
<a href="update.php?updateid=<?php echo $id;?>" class="badge badge-success">Update</a>
<a href="delete.php?deleteid=<?php echo $id; ?>" class="badge badge-danger delme" data-confirm="Are you sure you want to delete this item?">Delete</a>
</td>
</tr>
</tbody>
<?php } ?>
</table>
</div>
<tbody>
<tr>
<td><?php echo $row['firstName']; ?></td>
<td><?php echo $row['LastName']; ?></td>
<td><?php echo $row['email']; ?></td>
<td>
<a href="devDetails.php?devdetails=<?php echo $row['id']; ?>" class="badge badge-primary">Read</a>
<a href="update.php?updateid=<?php echo $row['id']; ?>" class="badge badge-success">Update</a>
<a href="delete.php?deleteid=<?php echo $row['id']; ?>" class="badge badge-danger delme" data-confirm="Are you sure you want to delete this item?">Delete</a>
</td>
</tr>
</tbody>
<?php } ?>
</table>
</div>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script>

$('A[data-confirm]').on("click", function (e)
{
<script>
$('A[data-confirm]').on("click", function(e) {
e.preventDefault();

var choice = confirm($(this).attr('data-confirm'));

if (choice)
{
if (choice) {
window.location.href = $(this).attr('href');
}
}
});

</script>
</script>
</body>
</html>

</html>
35 changes: 12 additions & 23 deletions delete.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
<?php

$con=mysqli_connect("localhost","root","","crudphp");
<?php

//checking the connection
if(mysqli_connect_errno())
{
echo "Unable to connect to the database : " .mysqli_connect_error();
}
include "./app/connection.php";
include "./app/helpers.php";

$delete_id=$_GET['deleteid'];
$query= "delete from developerdetails where id='$delete_id'";

if(mysqli_query($con,$query))
{
echo "<script>alert('Details Deleted')</script>";
echo "<script>location.href='dashboard.php'</script>";
}

else
{
echo "Unable to Delete the details";
}


?>
$delete_id = filter($_GET['deleteid']);
$query = $pdo->prepare("DELETE FROM developerdetails WHERE id = ?");
$query->bindParam(1, $delete_id);
if ($query->execute()) {
echo "<script>alert('Details Deleted')</script>";
echo "<script>location.href='dashboard.php'</script>";
} else {
echo "Unable to Delete the details";
}
Loading