Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Nov 21st, 2018 66 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. <?php
  2. include("dbcon.php");
  3. session_start();
  4. if(!isset($_SESSION['user']) && empty($_SESSION['user']))
  5. header("Location:login.php");
  6. $sql = "SELECT * FROM dept";
  7. $result=$con->query($sql);
  8. ?>
  9. <?php
  10. if(isset($_POST) && !empty($_POST)){
  11. //echo  "<pre>" ;print_r($_POST);exit;
  12. $name=$_POST['name'];
  13. $deptid=$_POST['deptid'];
  14. $sal=$_POST['sal'];
  15.  
  16. $sql="INSERT INTO emp(name,deptid,sal) VALUES('$name',$deptid,$sal)";
  17. if($con->query($sql))
  18. {
  19.     echo "<h3>Employee Added.</h3>";
  20.     echo "<a href='employees.php'>Back to List</a>";
  21.  
  22. }
  23.  
  24. else
  25. {
  26.     echo $con->error;
  27. }
  28. }
  29.  
  30. else{?>
  31.  
  32. <html>
  33. <head>
  34. <title>Add Employee: <?php echo $_SESSION['user']['name'];?></title>
  35. </head>
  36. <body>
  37. <h2>Add Employee</h2>
  38. <form name="addemp" action="<?php echo $_SERVER['PHP_SELF']?>" method="POST">
  39. Name:<input type="text" name="name" ><br>
  40. Department:<select name="deptid">
  41.              <option value="">Select Department</option>
  42.              <?php while($row=$result->fetch_assoc())
  43.              { ?>
  44.              <option value="<?php echo $row['id']; ?>"><?php echo $row['name']; ?></option>
  45.              <?php } ?>
  46.            </select><br>
  47. Salary:<input type="number" name="sal"><br>
  48. <input type="submit" value="Save"><br>
  49. <input type="reset" value="Cancel"><br>
  50. </form>
  51.  
  52.  
  53. </body>
  54. </html>
  55. <?php  } ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top