Advertisement
Guest User

Untitled

a guest
Jul 31st, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.74 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="number" 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.            
  39.         }
  40.        
  41.         $iq="INSERT INTO `wps2016f`.`employee` (`emp_id`, `emp_dept`, `emp_salary`) VALUES ('$id', '$dept', '$salary');";
  42.           mysqli_query($link,$iq);
  43.         //$sq="SELECT * from employee where `emp_salary`>2000 and `emp_salary`<6000 order by `emp_dept` ;";
  44.         $sq="SELECT * from employee;";
  45.         //step3: Execute query
  46.         $result=mysqli_query($link,$sq);
  47.         if(!$result)
  48.         {
  49.          die("Could not run the query".mysql_error()); 
  50.         }
  51.         else
  52.         {
  53.          while($row=mysqli_fetch_row($result))
  54.          {
  55.              echo"<tr>";
  56.                echo"<td>$row[0]</td>";
  57.                echo"<td>$row[1]</td>";
  58.                echo"<td>$row[2]</td>";
  59.              echo"</tr>";
  60.              
  61.          }           
  62.  
  63. $query=mysqli_query($link, "SELECT * FROM `employee` WHERE `emp_dept` = 'Business' OR `emp_dept` = 'FAST'");
  64.  
  65.  
  66.  
  67.         }
  68.     }
  69.   ?>
  70.  </table>
  71. </body>
  72. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement