Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>PHP+MySQL</title>
- </head>
- <body>
- <form action="" method="POST">
- <input type="text" name="id" placeholder="Employee Id"/>
- <input type="text" name="dept" placeholder="Employee Department"/>
- <input type="number" name="salary" placeholder="Employee Salary"/>
- <input type="submit" name="submit" value="Insert"/>
- </form>
- <table border="5" align="center" style="font-size:25px; background:gray;color:white">
- <caption style="color:black">Employee Information Table</caption>
- <thead>
- <td>Employee ID</td>
- <td>Employee Department</td>
- <td>Employee Salary</td>
- </thead>
- <?php
- $host="localhost";
- $user="root";
- $pass="root";
- $db="wps2016f";
- //step 1:MySQL connectivity
- $link=mysqli_connect($host,$user,$pass,$db);
- if(!$link)
- {
- die("Could not connect to MySQL".mysql_error());
- }
- else
- {
- if(isset($_POST['submit']))
- {
- $id=$_POST['id'];
- $dept=$_POST['dept'];
- $salary=$_POST['salary'];
- $check = mysqli_query($link,"SELECT * FROM employee WHERE emp_id LIKE $id");
- $exist = count($check);
- $iq="INSERT INTO `wps2016f`.`employee` (`emp_id`, `emp_dept`, `emp_salary`) VALUES ('$id', '$dept', '$salary');";
- if ($exist = 0) {
- mysqli_query($link,$iq);
- }
- else {
- echo "The record couldn’t be created as the emp_id duplicates (already exists)";
- }}
- //$sq="SELECT * from employee where `emp_salary`>2000 and `emp_salary`<6000 order by `emp_dept` ;";
- $sq="SELECT * from employee;";
- //step3: Execute query
- $result=mysqli_query($link,$sq);
- if(!$result)
- {
- die("Could not run the query".mysql_error());
- }
- else
- {
- while($row=mysqli_fetch_row($result))
- {
- echo"<tr>";
- echo"<td>$row[0]</td>";
- echo"<td>$row[1]</td>";
- echo"<td>$row[2]</td>";
- echo"</tr>";
- }
- echo "<br>";
- echo "<br>";
- $query=mysqli_query($link, "SELECT * FROM `employee` WHERE `emp_dept` = 'Business' OR `emp_dept` = 'FAST'");
- while($row=mysqli_fetch_row($query))
- {
- echo"<tr>";
- echo"<td>$row[0] <p> the follow Employee belongs to the Business or FAST Department
- </td>";
- echo"<td>$row[1]</td>";
- echo"<td>$row[2]</td>";
- echo"</tr>";
- }
- mysqli_query("ALTER TABLE 'employee' CHANGE 'emp_dept' 'emp_Dept' VARCHAR(255)");
- $findJohn = mysqli_query($link, "SELECT * FROM employee WHERE `emp_Dept` NOT LIKE 'FAST' AND emp_id LIKE 'John'");
- while($row=mysqli_fetch_row($findJohn))
- {
- echo"<tr>";
- echo"<td>$row[0] <p> John where NOT in emp_Dept FAST </p> </td>";
- echo"<td>$row[1]</td>";
- echo"<td>$row[2]</td>";
- echo"</tr>";
- }
- mysqli_query($link, "DELETE FROM employee WHERE emp_Dept LIKE 'Library'");
- }
- }
- # QUESTION FIVE WORKS NOW, IT WAS JUST NOT DONE SEQUENTIALLY BECAUSE OF THE TIME CONSTRAINS I AM CURRENTLY UNDER, PLEASE REVIEW THE ABOVE CODE Q 5 IS FUNCTIONAL
- #Lines 33-52 have been altered to meet the requirements of the code
- ?>
- </table>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement