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 #8

Open
wants to merge 3 commits 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
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@

## This test includes multiple stages

## STAGE - 1
## STAGE - 1(Done)

1. Create a table name details under database details with columns name, phone, email.
2. Create a php page called connect.php and write code to connect to the database.

## STAGE - 2
## STAGE - 2(Done)

1. Create insert.php and include connect.php
2. Insert 5 rows of data using php.

## STAGE - 3
## STAGE - 3(Done)

1. Create select.php
2. Select all data and print in a table format.
3. Select particular data using name constraint and print in table format.

## STAGE - 4
## STAGE - 4(Done)

1. Create delete.php
2. Delete a row with email as a constraint.

## STAGE - 5
## STAGE - 5(Done)

1. Create a webpage which includes buttons delete, insert, select.
2. The respect pages and their functionality should be done on click of each button.

## STAGE - 6
## STAGE - 6(Not Working)

1. Use ajax call to send and recieve data between the frontend and the backend.

Expand Down
4 changes: 4 additions & 0 deletions connect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
$db=new mysqli('localhost','root','','details');

?>
22 changes: 22 additions & 0 deletions delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php include'connect.php'; ?>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<br>
<form method="post" action="delete.php">
<center>
<input type="email" name="deleteopt" placeholder="Enter email to delete record" class="form-control" style="width: 30%;"><br>
<button type="submit" name="delete" class="btn btn-danger">Delete</button></center>
<?php
$flag=0;
if(isset($_POST['delete']))
{

$var=$_POST['deleteopt'];
$qry="DELETE FROM details WHERE email='$var'";
$db->query($qry);
}
?>
</form>
10 changes: 10 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<br><center>
<a href="select.php"><button class="btn btn-info" >Select</button></a>
<a href="insert.php"><button class="btn btn-success">Insert</button></a>
<a href="delete.php"><button class="btn btn-danger">Delete</button></a>
</center>
12 changes: 12 additions & 0 deletions insert.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php include'connect.php';
$var1="INSERT INTO details(name,phone,email) VALUES ('Siraj','9876543210','[email protected]')";
$var2="INSERT INTO details(name,phone,email) VALUES ('Rashid','9753186420','[email protected]')";
$var3="INSERT INTO details(name,phone,email) VALUES ('Williamson','9988776655','[email protected]')";
$var4="INSERT INTO details(name,phone,email) VALUES ('Mushfiqur','8976545678','[email protected]')";
$var5="INSERT INTO details(name,phone,email) VALUES ('Malinga','8877996644','[email protected]')";
$db->query($var1);
$db->query($var2);
$db->query($var3);
$db->query($var4);
$db->query($var5);
?>
93 changes: 93 additions & 0 deletions select.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php include'connect.php';
?>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style type="text/css">
tr:nth-child(odd) {
background-color: #5e90e0;
}
</style>
<script>
function showUser(str) {
if (str == "") {
document.getElementById("showshow").innerHTML = "";
return;
} else
{
if (window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("showshow").innerHTML = this.responseText;
}
};
xmlhttp.open("GET","select.php?a="+str,true);
xmlhttp.send();
}
}
</script>
</head>
<br>
<center>
<table class="table table-hover">
<tr>
<th>S.No</th>
<th>Name</th>
<th>Phone</th>
<th>Mail</th>
</tr>
<?php
$selectvar="SELECT * FROM details";
$temp=$db->query($selectvar);
while ($row = $temp->fetch_assoc())
{
?>
<tr>
<td><?php echo $row["sno"]; ?></td>
<td><?php echo $row["name"]; ?></td>
<td><?php echo $row["phone"]; ?></td>
<td><?php echo $row["email"]; ?></td>
</tr>
<?php
}
?>


</table>
<form >
<input id="showTableBtn" class="form-control" style="width: 30%" type="text" name="fieldname" placeholder="Enter name to display data"><br>
<button class="btn btn-primary" type="submit" name="enter" onsubmit="showUser((#showTableBtn).value)">Get details!</button>

<div id="showshow"></div>
<table id="dataTable" class="table table-hover">
<tr>
<th>S.No</th>
<th>Name</th>
<th>Phone</th>
<th>Mail</th>
</tr>
<?php
$a= $_GET['fieldname'];
$dispvar="SELECT * FROM details WHERE name='$a'";
$tempo=$db->query($dispvar);
while ($row = $tempo->fetch_assoc())
{
?>
<tr>
<td><?php echo $row["sno"]; ?></td>
<td><?php echo $row["name"]; ?></td>
<td><?php echo $row["phone"]; ?></td>
<td><?php echo $row["email"]; ?></td>
</tr>
<?php
}
?>
</table>
</form>
</center>