Advertisement
Guest User

Untitled

a guest
Aug 18th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>PHP+MySQL</title>
  4. </head>
  5. <body>
  6. <form action="" method="POST">
  7. <input type="text" name="id" placeholder="Employee Id"/>
  8. <input type="text" name="dept" placeholder="Employee Department"/>
  9. <input type="number" name="salary" placeholder="Employee Salary"/>
  10. <input type="submit" name="submit" value="Insert"/>
  11. </form>
  12.  
  13. <table border="5" align="center" style="font-size:25px; background:gray;color:white">
  14. <caption style="color:black">Employee Information Table</caption>
  15. <thead>
  16. <td>Employee ID</td>
  17. <td>Employee Department</td>
  18. <td>Employee Salary</td>
  19. </thead>
  20. <?php
  21. $host="localhost";
  22. $user="root";
  23. $pass="root";
  24. $db="wps2016f";
  25. //step 1:MySQL connectivity
  26. $link=mysqli_connect($host,$user,$pass,$db);
  27. if(!$link)
  28. {
  29. die("Could not connect to MySQL".mysql_error());
  30. }
  31. else
  32. {
  33. if(isset($_POST['submit']))
  34. {
  35. $id=$_POST['id'];
  36. $dept=$_POST['dept'];
  37. $salary=$_POST['salary'];
  38. $check = mysqli_query($link,"SELECT * FROM employee WHERE emp_id LIKE $id");
  39. $exist = count($check);
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46. $iq="INSERT INTO `wps2016f`.`employee` (`emp_id`, `emp_dept`, `emp_salary`) VALUES ('$id', '$dept', '$salary');";
  47. if ($exist = 0) {
  48. mysqli_query($link,$iq);
  49. }
  50. else {
  51. echo "The record couldn’t be created as the emp_id duplicates (already exists)";
  52. }}
  53. //$sq="SELECT * from employee where `emp_salary`>2000 and `emp_salary`<6000 order by `emp_dept` ;";
  54. $sq="SELECT * from employee;";
  55. //step3: Execute query
  56. $result=mysqli_query($link,$sq);
  57. if(!$result)
  58. {
  59. die("Could not run the query".mysql_error());
  60. }
  61. else
  62. {
  63. while($row=mysqli_fetch_row($result))
  64. {
  65. echo"<tr>";
  66. echo"<td>$row[0]</td>";
  67. echo"<td>$row[1]</td>";
  68. echo"<td>$row[2]</td>";
  69. echo"</tr>";
  70.  
  71.  
  72.  
  73. }
  74.  
  75. echo "<br>";
  76. echo "<br>";
  77.  
  78.  
  79.  
  80. $query=mysqli_query($link, "SELECT * FROM `employee` WHERE `emp_dept` = 'Business' OR `emp_dept` = 'FAST'");
  81.  
  82. while($row=mysqli_fetch_row($query))
  83. {
  84.  
  85. echo"<tr>";
  86. echo"<td>$row[0] <p> the follow Employee belongs to the Business or FAST Department
  87. </td>";
  88. echo"<td>$row[1]</td>";
  89. echo"<td>$row[2]</td>";
  90. echo"</tr>";
  91.  
  92. }
  93.  
  94. mysqli_query("ALTER TABLE 'employee' CHANGE 'emp_dept' 'emp_Dept' VARCHAR(255)");
  95.  
  96. $findJohn = mysqli_query($link, "SELECT * FROM employee WHERE `emp_Dept` NOT LIKE 'FAST' AND emp_id LIKE 'John'");
  97.  
  98. while($row=mysqli_fetch_row($findJohn))
  99. {
  100.  
  101. echo"<tr>";
  102. echo"<td>$row[0] <p> John where NOT in emp_Dept FAST </p> </td>";
  103. echo"<td>$row[1]</td>";
  104. echo"<td>$row[2]</td>";
  105. echo"</tr>";
  106.  
  107. }
  108.  
  109. mysqli_query($link, "DELETE FROM employee WHERE emp_Dept LIKE 'Library'");
  110.  
  111.  
  112. }
  113. }
  114.  
  115. # 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
  116. #Lines 33-52 have been altered to meet the requirements of the code
  117. ?>
  118. </table>
  119. </body>
  120. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement