Answer to Question #192520 in HTML/JavaScript Web Application for Dianalyn Pagsanjan

Question #192520

create page that . Has the functionality to upload pictures and a description of the picture. Use HTML, PHP, or JavaScript. Please show the database SQL code


1
Expert's answer
2021-05-13T07:15:36-0400
<!DOCTYPE html>
<html lang="en">
  
<head>
    <title>Web Page</title>
</head>
  
<body>
        <h1>Database Operations</h1>
        <form action="perform.php" method="post">
                <select name="perform">
                        <option selected disabled hidden style='display: none' value=''></option>
                        <option value="insertion">insert</option>
                        <option value="update">update</option>
                        <option value="read">read</option>
                        <option value="delete">delete</option>
                </select>
                <input type="submit" name="submit" value="Submit" />
        </form>

</body>
  
</html>


Perform.php


<!DOCTYPE html>
<html>
  
<head>
    <title>WebPage</title>
</head>
  
<body>
        <?php
                if(isset($_POST['submit']))
                {
                        if(isset($_POST['perform']))
                        {
                                $selected_val = $_POST['perform'];  
                                switch ($selected_val) 
                                {
                                        case "insert":
                                                header("Location:home.php"); 
                                                break;
                                        case "update":
                                                header("Location:home1.php");
                                                break;
                                        case "read":
                                                header("Location:home2.php");
                                                break;
                                        case "delete":
                                                header("Location:home3.php");
                                                break;
                                }
                        }
                        else
                        {
                                echo "Invalid Input";
                        }
                }
?>
</body>
  
</html>

home.php

<!DOCTYPE html>
<html lang="en">
  
<head>
    <title>WebPage</title>
</head>
  
<body>
    <center>
        <h1>Storing Data Into Database</h1>
        <table>
        <form action="insert.php" method="post">
        
        <tr>
                <td> <label for="emp_id"><b>Employee Id</label> </td>
                <td> <input type="text" name="emp_id" id="emp_id" required> </td>
        </tr>
  
        <tr>
                <td> <label for="emp_name"><b>Employee Name</label> </td>
                <td> <input type="text" name="emp_name" id="emp_Name" required> </td>
        </tr>
  
        <tr>
                <td> <label for="job"><b>Job</label> </td>
                <td> <input type="text" name="job" id="job" required> </td>
        </tr>

        <tr>
                <td> <label for="dept_id"><b>Department Id</label> </td>
                <td> <input type="text" name="dept_id" id="dept_id" required> </td> 
        </tr>

        <tr>
                <td> <label for="sal"><b>Salary</label> </td>
                <td> <input type="text" name="sal" id="sal" required> </td>
         </tr>

        <tr>
                <td colspan = "2" style="text-align:center;">
                <input type="submit" value="Submit"> </td>
        </tr>
        </form>
        </table>
    </center>
</body>
  
</html>

Insert.php

<!DOCTYPE html>
<html>
  
<head>
    <title>WebPage</title>
</head>
  
<body>
    <center>
        <?php
        $conn = mysqli_connect("localhost", "root", "", "project");

        if($conn === false){
            die("ERROR: Could not connect. ". mysqli_connect_error());
        }
          

        $emp_id =  $_REQUEST['emp_id'];
        $emp_name = $_REQUEST['emp_name'];
        $job =  $_REQUEST['job'];
        $dept_id = $_REQUEST['dept_id'];
        $sal = $_REQUEST['sal'];

        $sql = "INSERT INTO employee  VALUES ('$emp_id', '$emp_name','$job','$dept_id','$sal')";
          
        if(mysqli_query($conn, $sql)){
            echo "<h3>data stored in a database successfully.";
        } else{
            echo "ERROR: Occured! $sql. ". mysqli_error($conn);
        }
        mysqli_close($conn);
        ?>
    </center>
</body>
  
</html>

home1.php

<!DOCTYPE html>
<html lang="en">
  
<head>
    <title>WebPage</title>
</head>
  
<body>
    <center>
        <h1>Updating Data Into Database</h1>
        <table>
        <form action="update.php" method="post">
        
        <tr>
                <td> <label for="emp_id"><b>Employee Id</label> </td>
                <td> <input type="text" name="emp_id" id="emp_id" required> </td>
        </tr>
  
        <tr>
                <td> <label for="emp_name"><b>Employee Name</label> </td>
                <td> <input type="text" name="emp_name" id="emp_Name"> </td>
        </tr>
  
        <tr>
                <td> <label for="job"><b>Job</label> </td>
                <td> <input type="text" name="job" id="job"> </td>
        </tr>

        <tr>
                <td> <label for="dept_id"><b>Department Id</label> </td>
                <td> <input type="text" name="dept_id" id="dept_id"> </td> 
        </tr>

        <tr>
                <td> <label for="sal"><b>Salary</label> </td>
                <td> <input type="text" name="sal" id="sal"> </td>
         </tr>

        <tr>
                <td colspan = "2" style="text-align:center;">
                <input type="submit" value="Submit"> </td>
        </tr>
        </form>
        </table>
    </center>
</body>
  
</html>

update.php

<!DOCTYPE html>
<html>
  
<head>
    <title>WebPage</title>
</head>
  
<body>
    <center>
        <?php
        $conn = mysqli_connect("localhost", "root", "", "project");

        if($conn === false){
            die("ERROR: Could not connect. ". mysqli_connect_error());
        }

        $emp_id =  $_REQUEST['emp_id'];
        $emp_name = $_REQUEST['emp_name'];
        $job =  $_REQUEST['job'];
        $dept_id = $_REQUEST['dept_id'];
        $sal = $_REQUEST['sal'];

        $sql = "UPDATE EMPLOYEE SET ename = '$emp_name', job = '$job', deptid = $dept_id, sal = $sal where empid = $emp_id ";
          
        if(mysqli_query($conn, $sql)){
            echo "<h3>data updated in a database successfully from."."<br>";        
        } else{
            echo "ERROR: Occured! $sql. ". mysqli_error($conn);
        }
        mysqli_close($conn);
        ?>
    </center>
</body>
  
</html>

home2.php

<!DOCTYPE html>
<html lang="en">
  
<head>
    <title>WebPage</title>
</head>
  
<body>
    <center>
        <h1>Reading Data From Database</h1>
        <table>
        <form action="read.php" method="post">
        
        <tr>
                <td> <label for="emp_id"><b>Employee Id</label> </td>
                <td> <input type="text" name="emp_id" id="emp_id" required> </td>
        </tr>

        <tr>
                <td colspan = "2" style="text-align:center;">
                <input type="submit" value="Submit"> </td>
        </tr>
        </form>
        </table>
    </center>
</body>
  
</html>

read.php

<!DOCTYPE html>
<html>
  
<head>
    <title>WebPage</title>
</head>
  
<body>
    <center>
        <table class="table table-hover">
          <tr>
              <th>EmpId</th>
              <th>Name</th>
              <th>Job</th>
              <th>DeptId</th>
              <th>Sal</th>
          </tr>
        <tr>
        <?php
        $conn = mysqli_connect("localhost", "root", "", "project");

        if($conn === false){
            die("ERROR: Could not connect. ". mysqli_connect_error());
        }
          

        $emp_id =  $_REQUEST['emp_id'];

        $sql = "SELECT * FROM employee WHERE empid = $emp_id";
        $result = mysqli_query($conn, $sql);

        if (mysqli_num_rows($result) > 0) 
        {
                while($row = mysqli_fetch_assoc($result)) 
                {       
                        ?>
                        <td><?php echo $row['empid']; ?></td>
                        <td><?php echo $row['ename']; ?></td>
                        <td><?php echo $row['job']; ?></td>
                        <td><?php echo $row['deptid']; ?></td>
                        <td><?php echo $row['sal']; ?></td>
                        <?php                                        
                }
        }
        else
        {
                echo "0 results";
        }
        ?>
        </tr>
    </table>
    </center>
</body>
  
</html>

home3.php

<!DOCTYPE html>
<html lang="en">
  
<head>
    <title>WebPage</title>
</head>
  
<body>
    <center>
        <h1>Deleting Data From Database</h1>
        <table>
        <form action="delete.php" method="post">
        
        <tr>
                <td> <label for="emp_id"><b>Employee Id</label> </td>
                <td> <input type="text" name="emp_id" id="emp_id" required> </td>
        </tr>

        <tr>
                <td colspan = "2" style="text-align:center;">
                <input type="submit" value="Submit"> </td>
        </tr>
        </form>
        </table>
    </center>
</body>
  
</html>

delete.php

<!DOCTYPE html>
<html>
  
<head>
    <title>WebPage</title>
</head>
  
<body>
    <center>
        <?php
        $conn = mysqli_connect("localhost", "root", "", "project");

        if($conn === false){
            die("ERROR: Could not connect. ". mysqli_connect_error());
        }
          

        $emp_id =  $_REQUEST['emp_id'];

        $sql = "DELETE FROM employee WHERE empid = $emp_id";
          
        if(mysqli_query($conn, $sql)){
            echo "<h3>data Deleted in a database successfully.";
        } else{
            echo "ERROR: Occured! $sql. ". mysqli_error($conn);
        }
        mysqli_close($conn);
        ?>
    </center>
</body>
  
</html>

Dtabase :

drop database project;

create database project;
use project;

CREATE TABLE dept (
deptid INT,
dname VARCHAR(20),
dloc VARCHAR(20),
PRIMARY KEY (deptid)
);

CREATE TABLE employee (
empid INT,
ename VARCHAR(20),
job VARCHAR(20),
deptid INT,
sal INT,
PRIMARY KEY (empid),
CONSTRAINT fk_employee_dept FOREIGN KEY (deptid)
REFERENCES dept (deptid)
);

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS