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 Ajith #12

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
15 changes: 15 additions & 0 deletions connect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
$servername = "127.0.0.1";
$username = "root";
$password = "";
$db="details";

// Create connection
$conn = new mysqli($servername, $username, $password, $db);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
17 changes: 17 additions & 0 deletions delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<html>
<head>
</head>
<body>
<form action="delete.php" method="post">
Enter the email of the data to be deleted<input type="text" name="emailf"><br>
<input type="submit"><br>

</form>
<button value="home" onclick="window.location.href='webpage.php';">Home</button>
</body>
</html>
<?php
require("connect.php");
$email=$_POST["emailf"];
$conn->query("DELETE FROM details WHERE email='$email'");
?>
29 changes: 29 additions & 0 deletions insert.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<html>
<body>

<form action="insert.php" method="post">
Name: <input type="text" name="namea"><br>
Phone: <input type="text" name="phone1"><br>
E-mail: <input type="text" name="email1"><br>
<br><br>
Name: <input type="text" name="nameb"><br>
Phone: <input type="text" name="phone2"><br>
E-mail: <input type="text" name="email2"><br>
<br><br>
Name: <input type="text" name="namec"><br>
Phone: <input type="text" name="phone3"><br>
E-mail: <input type="text" name="email3"><br>
<br><br>
Name: <input type="text" name="named"><br>
Phone: <input type="text" name="phone4"><br>
E-mail: <input type="text" name="email4"><br>
<br><br>
Name: <input type="text" name="namee"><br>
Phone: <input type="text" name="phone5"><br>
E-mail: <input type="text" name="email5"><br>
<input type="submit"><br>
</form>
<button value="home" onclick="window.location.href='webpage.php';">Home</button>
</body>
</html>
<button onclick=""
67 changes: 67 additions & 0 deletions insert.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
require 'connect.php'?>

<?php
$namea = $email1 = $phone1 ="";
$nameb = $email2 = $phone2 ="";
$namec = $email3 = $phone3 ="";
$named = $email4 = $phone4 ="";
$namee = $email5 = $phone5 ="";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$namea = test_input($_POST["namea"]);
$email1 = test_input($_POST["email1"]);
$phone1= test_input($_POST["phone1"]);
$nameb = test_input($_POST["nameb"]);
$email = test_input($_POST["email2"]);
$phone2= test_input($_POST["phone2"]);
$namec = test_input($_POST["namec"]);
$email3 = test_input($_POST["email3"]);
$phone3= test_input($_POST["phone3"]);
$named = test_input($_POST["named"]);
$email4 = test_input($_POST["email4"]);
$phone4= test_input($_POST["phone4"]);
$namee= test_input($_POST["namee"]);
$email5 = test_input($_POST["email5"]);
$phone5= test_input($_POST["phone5"]);

}

function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<?php
$namea= $_POST["namea"];
$phone1 = $_POST["phone1"];
$email1 = $_POST["email1"];
$nameb = $_POST["nameb"];
$phone2 = $_POST["phone2"];
$email2 = $_POST["email2"];
$namec = $_POST["namec"];
$phone3 = $_POST["phone3"];
$email3 = $_POST["email3"];
$named = $_POST["named"];
$phone4 = $_POST["phone4"];
$email4 = $_POST["email4"];
$namee = $_POST["namee"];
$phone5 = $_POST["phone5"];
$email5 = $_POST["email5"];

$sql = "INSERT INTO details (Name , Phone, Email)
VALUES ('$namea', '$phone1', '$email1'),('$nameb', '$phone2', '$email2'),('$namec', '$phone3', '$email3'),('$named', '$phone4', '$email4'),('$namee', '$phone5', '$email5')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>
<html>
<body>
<button value="back" onclick="window.location.href='insert.html';">BACK</button>
</body>
</html>
39 changes: 39 additions & 0 deletions select.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<head>
<style>
table {
width: 100%;
border-collapse: collapse;
}
table, td, th {
border: 2px solid black;
}
th {text-align: left;}
</style>
</head>
<body>
<?php

require("connect.php");
$sql="SELECT * FROM details";
$res = $conn->query($sql);
?>
<table>
<tr>
<th>Name</th>
<th>Phone</th>
<th>Email</th>
</tr>
<?php
while($row = $res->fetch_array()) {
echo "<tr>";
echo "<td>" . $row['Name'] . "</td>";
echo "<td>" . $row['Phone'] . "</td>";
echo "<td>" . $row['Email'] . "</td>";
echo "</tr>";
}
?></table>
<button value="home" onclick="window.location.href='webpage.php';">Home</button>
</body>
</html>
43 changes: 43 additions & 0 deletions select2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html>
<head>
<style>
table {
width: 100%;
border-collapse: collapse;
}
table, td, th {
border: 2px solid black;
}
th {text-align: left;}
</style>
</head>
<body>
<form method="get">
Name: <input type="text" name="query"><br>
<input type="submit">
</form>
<?php
$query = $_GET['query'];
require("connect.php");
$sql="SELECT * FROM details WHERE name = '".$query."'";
$res = $conn->query($sql);
?>
<table>
<tr>
<th>Name</th>
<th>Phone</th>
<th>Email</th>
</tr>
<?php
while($row = $res->fetch_array()) {
echo "<tr>";
echo "<td>" . $row['Name'] . "</td>";
echo "<td>" . $row['Phone'] . "</td>";
echo "<td>" . $row['Email'] . "</td>";
echo "</tr>";
}
?></table>
<button value="home" onclick="window.location.href='webpage.php';">Home</button>
</body>
</html>
8 changes: 8 additions & 0 deletions webpage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<body>
<button value="select" onclick="window.location.href='select.php';">Select All</button>
<button value="select2" onclick="window.location.href='select2.php';">Select By Name</button>
<button value="insert" onclick="window.location.href='insert.html';">Insert</button>
<button value="delete" onclick="window.location.href='delete.php';">Delete</button>
</body>
</html>