Skip to content

Commit

Permalink
CRUD APLLICATION USING PHP AND MYSQL
Browse files Browse the repository at this point in the history
  • Loading branch information
njuguna036 committed Apr 12, 2022
0 parents commit 63a55bd
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 0 deletions.
19 changes: 19 additions & 0 deletions delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
include 'connect.php';
if(isset($_GET['deleteid']))
{
$id=$_GET['deleteid'];
$sql= "DELETE FROM `added` WHERE `added`.`id`=$id";
$result=mysqli_query($con,$sql);
if ($result)
{
header('location:display.php');
}else{
die(mysqli_error($con));
}
}




?>
61 changes: 61 additions & 0 deletions display.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
include 'connect.php';
?>
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="main.css">
</head>
<body>
<div class="container">
<br>
<button class="btn btn-primary"><a href="main.php">add user</a>
</button>
<table>
<thead>
<tr>
<th scope="col">sl</th>
<th scope="col">name</th>
<th scope="col">email</th>
<th scope="col">mobile</th>
<th scope="col">password</th>
<th scope="col">operation</th>
</tr>

</thead>
<tbody>

<?php
$sql="SELECT * FROM `added` ORDER BY `id` ASC";
$result=mysqli_query($con,$sql);
if($result){
while($row=mysqli_fetch_assoc($result)){
$id=$row['id'];
$name=$row['name'];
$email=$row['email'];
$mobile=$row['mobile'];
$password=$row['password'];
echo '<tr>
<td>'.$id.'</td>
<td>'.$name.'</td>
<td>'.$email.'</td>
<td>'.$mobile.'</td>
<td>'.$password.'</td>
<td>
<button><a href="delete.php? deleteid='.$id.'">delete</a></button>
<button><a href="update.php?updateid='.$id.'">update</a></button>
</td>
</tr>';
}
}



?>
</tbody>
</table>
</div>
</body>
</html>
14 changes: 14 additions & 0 deletions main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
body{
background-color: powderblue;
margin-left: 4px;
}
button{
background-color: rgb(0, 255, 64);
}
.container{
text-align: center;
justify-content: center;
align-items: center;
width: 1050px;
font-size:x-large;
}
71 changes: 71 additions & 0 deletions update.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

include 'connect.php';
$id=$_GET['updateid'];
if(isset($_POST['submit'])){

$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['mobile'];
$password=$_POST['password'];



$sql="UPDATE `added` SET `name` = '$name', `email` = '$email', `mobile` = '$phone', `password` = '$password'
WHERE `added`.`id` =$id";

$result=mysqli_query($con,$sql);
if ($result)
{
header('location:display.php');
}else{
die(mysqli_error($con));
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>addt</title>
<link rel="stylesheet" href="main.css">
</head>
<body>
<div class="container my-5">
<<form method = "post" action = "<?php $_PHP_SELF ?>">
<div class=""form-group>
<label >name</label>
<br>
<input type="text" name="name" class="form-control" placeholder="Enter you name">
<br>

</div>
<div class="form-group">
<label >Email</label>
<br>
<input type="email" name="email" class="form-control" placeholder="Enter your email">
<br>

</div>
<div class="form-group">
<label >phone number</label>
<br>
<input type="text" name="mobile" class="form-control" placeholder="Enter you phone number">
<br>

</div>
<div class="form-group">
<label >password</label>
<br>
<input type="password" name="password" class="form-control" placeholder="Enter your password">
<br>

</div>
<br>
<button type="submit" name="submit">update</button>
</form>
</div>
</body>
</html>

0 comments on commit 63a55bd

Please sign in to comment.