Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //index.php
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <style>
- form {
- font-size: 1.2rem;
- }
- form div{
- margin: 10px;
- }
- h1{
- text-align: center;
- }
- </style>
- <script defer>
- var form = document.querySelector('form');
- function postAction(){
- form.setAttribute("action","insert.php");
- form.submit();
- }
- </script>
- <title>Form</title>
- </head>
- <body>
- <form action="no.php" method="post">
- <h1>Employee ID</h1>
- <fieldset style="display:flex;flex-flow:row nowrap;">
- <div style="display:flex;flex-flow:column nowrap;gap:20px;">
- <div>
- <label for="empid">Employee ID: </label>
- <input type="number" name="id" id="empid" required/>
- </div>
- <div>
- <label for="empname">Employee Name:</label>
- <input type="text" name="name" id="empname"/>
- </div>
- <div>
- <label for="empdept">Employee Dept:</label>
- <input type="text" name="dept" id="empdept"/>
- </div>
- <div>
- <label for="emppos">Employee Position:</label>
- <input type="text" name="pos" id="emppos"/>
- </div>
- </div>
- <div style="display:flex;flex-flow:column nowrap;gap: 20px;">
- <input type="submit" value="Insert" formaction="insert.php">
- <input type="submit" value="Update" formaction="update.php">
- <input type="submit" value="Delete" formaction="delete.php">
- <input type="submit" value="Search" formaction="dynamic.php">
- <input type="submit" value="View" formaction="display.php">
- <input type="reset" value="Reset">
- </div>
- </fieldset>
- </form>
- </body>
- </html>
- //dynamic.php
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <style>
- form {
- font-size: 1.2rem;
- }
- form div{
- margin: 10px;
- }
- h1{
- text-align: center;
- }
- </style>
- <script defer>
- var form = document.querySelector('form');
- function postAction(){
- form.setAttribute("action","insert.php");
- form.submit();
- }
- </script>
- <title>Form</title>
- </head>
- <body>
- <form action="no.php" method="post">
- <h1>Employee ID</h1>
- <fieldset style="display:flex;flex-flow:row nowrap;">
- <?php
- $hostname = "localhost";
- $username = "root";
- $password = "";
- $database = "urmum";
- $conn = mysqli_connect($hostname, $username, $password, $database);
- if(!$conn){
- die("Connection failed: ".mysqli_connect_error());
- }
- else{
- $id = $_POST["id"];
- $query = "SELECT * from daemployees where empid = $id";
- $res = mysqli_query($conn, $query);
- if(mysqli_num_rows($res) > 0){
- $row = mysqli_fetch_assoc($res);
- $id = $_POST["id"];
- $name = $_POST["name"];
- $dept = $_POST["dept"];
- $pos = $_POST["pos"];
- echo "
- <div style=\"display:flex;flex-flow:column nowrap;gap:20px;\">
- <div>
- <label for=\"empid\">Employee ID: </label>
- <input type=\"number\" name=\"id\" id=\"empid\" value=\"".$row['empid']."\" required/>
- </div>
- <div>
- <label for=\"empname\">Employee Name:</label>
- <input type=\"text\" name=\"name\" id=\"empname\" value=\"".$row['empname']."\"/>
- </div>
- <div>
- <label for=\"empdept\">Employee Dept:</label>
- <input type=\"text\" name=\"dept\" id=\"empdept\" value=\"".$row['empdept']."\"/>
- </div>
- <div>
- <label for=\"emppos\">Employee Position:</label>
- <input type=\"text\" name=\"pos\" id=\"emppos\" value=\"".$row['emppos']."\"/>
- </div>
- </div>
- <div style=\"display:flex;flex-flow:column nowrap;gap: 20px;\">
- <input type=\"submit\" value=\"Insert\" formaction=\"insert.php\">
- <input type=\"submit\" value=\"Update\" formaction=\"update.php\">
- <input type=\"submit\" value=\"Delete\" formaction=\"delete.php\">
- <input type=\"submit\" value=\"Search\" formaction=\"search.php\">
- <input type=\"submit\" value=\"View\" formaction=\"display.php\">
- <input type=\"submit\" formaction=\"index.php\" value=\"Reset\">
- </div>";
- }
- else{
- echo "No data";
- }
- }
- ?>
- </div>
- </fieldset>
- </form>
- </body>
- </html>
- //insert.php
- <?php
- $hostname = "localhost";
- $username = "root";
- $password = "";
- $database = "urmum";
- $conn = mysqli_connect($hostname, $username, $password, $database);
- if(!$conn){
- die("Connection failed: ".mysqli_connect_error());
- }
- else{
- echo "Connection successful!";
- }
- $id = $_POST["id"];
- $name = $_POST["name"];
- $dept = $_POST["dept"];
- $pos = $_POST["pos"];
- $query = "INSERT INTO daemployees(empid, empdept, empname, emppos) VALUES ('$id','$dept','$name','$pos')";
- if( mysqli_query($conn, $query) ){
- echo "<br/>Data entered successfully";
- header("Location: display.php");
- exit;
- }
- else{
- echo "Even a donkey is more useful than you!!";
- }
- mysqli_close($conn);
- ?>
- //search.php
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>The Table</title>
- </head>
- <body>
- <?php
- $hostname = "localhost";
- $username = "root";
- $password = "";
- $database = "urmum";
- $conn = mysqli_connect($hostname, $username, $password, $database);
- if(!$conn){
- die("Connection failed: ".mysqli_connect_error());
- }
- else{
- $id = $_POST["id"];
- $query = "SELECT * from daemployees where empid = $id";
- $res = mysqli_query($conn, $query);
- if(mysqli_num_rows($res) > 0){
- echo "<table border='2' cellpadding='5' cellspacing='0'><tr>
- <th>ID</th>
- <th>Name</th>
- <th>Department</th>
- <th>Position</th>
- </tr>";
- $row = mysqli_fetch_assoc($res);
- echo "<tr>
- <td>" .$row['empid']. "</td>
- <td>" .$row['empname']. "</td>
- <td>" .$row['empdept']. "</td>
- <td>" .$row['emppos']. "</td>
- </tr>";
- echo "</table>";
- }
- else{
- echo "No Data.";
- }
- }
- mysqli_close($conn);
- ?>
- </body>
- </html>
- //update.php
- <?php
- $hostname = "localhost";
- $username = "root";
- $password = "";
- $database = "urmum";
- $conn = mysqli_connect($hostname, $username, $password, $database);
- if(!$conn){
- die("Connection failed: ".mysqli_connect_error());
- }
- else{
- echo "Connection successful!";
- }
- $id = $_POST["id"];
- $name = $_POST["name"];
- $dept = $_POST["dept"];
- $pos = $_POST["pos"];
- $query = "UPDATE daemployees SET empname='$name',empdept='$dept',emppos='$pos' WHERE empid = $id";
- echo $query;
- if( mysqli_query($conn, $query) ){
- echo "<br/>Entry updated Successfully";
- header("Location: display.php");
- exit;
- }
- else{
- echo "Even a donkey is more useful than you!!";
- }
- mysqli_close($conn);
- ?>
- //display.php
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>The Table</title>
- </head>
- <body>
- <?php
- $hostname = "localhost";
- $username = "root";
- $password = "";
- $database = "urmum";
- $conn = mysqli_connect($hostname, $username, $password, $database);
- if(!$conn){
- die("Connection failed: ".mysqli_connect_error());
- }
- else{
- $query = "SELECT * from daemployees";
- $res = mysqli_query($conn, $query);
- if(mysqli_num_rows($res) > 0){
- echo "<table border='2' cellpadding='5' cellspacing='0'><tr>
- <th>ID</th>
- <th>Name</th>
- <th>Department</th>
- <th>Position</th>
- </tr>";
- while( $row = mysqli_fetch_assoc($res) ){
- echo "<tr>
- <td>" .$row['empid']. "</td>
- <td>" .$row['empname']. "</td>
- <td>" .$row['empdept']. "</td>
- <td>" .$row['emppos']. "</td>
- </tr>";
- }
- echo "</table><form action=\"index.php\">
- <div><button type=\"submit\">Submit</button>
- </form></div>";
- }
- else{
- echo "No Data.";
- }
- }
- mysqli_close($conn);
- ?>
- </body>
- </html>
- //Delete.php
- <?php
- $hostname = "localhost";
- $username = "root";
- $password = "";
- $database = "urmum";
- $conn = mysqli_connect($hostname, $username, $password, $database);
- if(!$conn){
- die("Connection failed: ".mysqli_connect_error());
- }
- else{
- echo "Connection successful!";
- }
- $id = $_POST["id"];
- $name = $_POST["name"];
- $dept = $_POST["dept"];
- $pos = $_POST["pos"];
- $query = "DELETE FROM daemployees WHERE empid = $id;";
- echo $query;
- if( mysqli_query($conn, $query) ){
- echo "<br/>Entry Deleted Successfully";
- header("Location: display.php");
- exit;
- }
- else{
- echo "Even a donkey is more useful than you!!";
- }
- mysqli_close($conn);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement