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

php test #24

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
14 changes: 14 additions & 0 deletions connect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "details";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>
83 changes: 83 additions & 0 deletions delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@

<!DOCTYPE html>
<html lang="en">
<head>
<title>Delete</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<style>
td{
text-align: center;
}

.jumbotron1 {
width: 60%;
margin:0px;
}

.jumbotron1 form{
margin-left: 70px;
}

.jumbotron1 {
margin: auto;
position: ;
top: 0; left: 0; bottom: 0; right: 0;
}
#table_all{

}
</style>
}
</head>

<body>
<div class="container" style="">
<br>
<h3 class="text-center" style="background-color: #f0f0f0;">DELETE DATA</h3><br>
<div class="jumbotron1">

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

<div class="form-group row">
<label for="inputPassword3" class="col-sm-2 col-form-label">Mail :</label>
<div class="col-sm-6">
<input type="name" name="mail" class="form-control" id="inputname" placeholder="" required>
</div>
<button type="submit" name="delete" class="btn btn-danger" style="float: right;">Delete</button>
</div>
<br>
</form>

</div>
</div>

<div id="tabel_all" class="jumbotron1">
<?php
include 'connect.php';

if(isset($_POST['delete']))
{

$Mail=$_POST['mail'];
$quer="DELETE FROM `details` WHERE mail='$Mail'";
$result=mysqli_query($conn, $quer);
if($result)
{
?><div class="alert alert-warning">
<strong>Success!</strong> New Record added successfully.
</div>;
}
<?php
else
{
echo "Error: " . $quer . "<br>" . mysqli_error($conn);
}
}
?>
</div>
</body>
</html>
74 changes: 74 additions & 0 deletions getuser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<!DOCTYPE html>
<html>
<head>
<style>

#tab{
margin: auto;
position: ;
top: 0; left: 0; bottom: 0; right: 0;
width: 80%;
}

</head>
<body>

<?php
$q = intval($_GET['q']);
echo "string";
$con = mysqli_connect('localhost','root','','details');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
echo "hey";

$quer="SELECT * FROM `details` WHERE name='$q'";
$result=mysqli_query($conn, $quer);
if($result->num_rows > 0)
{?>
<table class="table table-bordered" id="tab">
<thead class="table-dark" >
<tr class="text-center">
<td>
Name
</td>
<td>
Phone
</td>
<td>
Mail
</td>
</tr>
</thead> <?php
while($row=mysqli_fetch_assoc($result))
{
?>
<tbody>
<tr>
<td>
<?php echo $row['name'];?>
</td>
<td>
<?php echo $row['phone'];?>
</td>
<td>
<?php echo $row['mail'];?>
</td>
</tr>

<?php
}?>
</tbody>
</table>
<?php

}
else
{
echo "Error: " . $quer . "<br>" . mysqli_error($conn);
}

mysqli_close($con);
?>
</body>
</html>
110 changes: 110 additions & 0 deletions insert.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@

<!DOCTYPE html>
<html lang="en">
<head>
<title>Insert</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<style>
.jumbotron1{
width: 60%;
margin:0px;
}
.jumbotron1 form{
margin-left: 70px;

}
.jumbotron1 {
margin: auto;
position: ;
top: 0; left: 0; bottom: 0; right: 0;

}

</style>
</head>

<body>
<br>
<div class="container" style="">
<h3 class="text-center" style="background-color: #f0f0f0;">INSERT DATA</h3><br>
<div class="jumbotron1">


<form method="post" action="insert.php" style="width: 100%;">

<div class="form-group row">
<label for="inputPassword3" class="col-sm-3 col-form-label">Name :</label>
<div class="col-sm-6">
<input type="name" name="name" class="form-control" id="inputname" placeholder="" required>
</div>
</div>

<div class="form-group row">
<label for="inputPassword3" class="col-sm-3 col-form-label">Phone :</label>
<div class="col-sm-6">
<input type="text" name="phone" class="form-control" id="inputphone" placeholder="" maxlength="10" required>
</div>
</div>

<div class="form-group row">
<label for="inputEmail3" class="col-sm-3 col-form-label">Email :</label>
<div class="col-sm-6">
<input type="email" name="mail" class="form-control" id="inputmail" placeholder="" required>
</div>
</div>



<br>
<div class="form-group row">
<div class="col-sm-5">
<button type="submit" name="submit" class="btn btn-success" style="float: right;">Insert</button>
</div>
</div>
</form>
</div>
</div>
</body>
</html>


<?php
include 'connect.php';

$name=$phone=$mail="";

if(isset($_POST['submit']))
{
$name=test_input($_POST['name']);
$phone=test_input($_POST['phone']);
$mail=test_input($_POST['mail']);
$quer="INSERT INTO `details`(`name`, `phone`, `mail`) VALUES ('$name','$phone','$mail')";

if (mysqli_query($conn, $quer))
{
?><div class="alert alert-success alert-dismissible">
<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
<strong>Success!</strong> New Record inserted successfully.
</div>
<?php
}
else
{
echo "Error: " . $quer . "<br>" . mysqli_error($conn);
}


}

//function for removing white space and special chars
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
Loading