Advertisement
Guest User

Untitled

a guest
Mar 9th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <!--
  3. To change this license header, choose License Headers in Project Properties.
  4. To change this template file, choose Tools | Templates
  5. and open the template in the editor.
  6. -->
  7. <html>
  8. <head>
  9. <meta charset="UTF-8">
  10. <title></title>
  11. </head>
  12. <body>
  13. <?php
  14.  
  15. if (isset($_POST['update'])) {
  16. $dbhost = '127.0.0.1';
  17. $dbuser = 'root';
  18. $dbpass = '';
  19. $db = 'lala';
  20.  
  21. $conn = mysqli_connect($dbhost, $dbuser, $dbpass);
  22.  
  23. if (!$conn) {
  24. die("Fallo en conexión: " . mysqli_error());
  25.  
  26. }
  27.  
  28. $db_select = mysqli_select_db($conn, $db);
  29.  
  30. if (!$db_select) {
  31. die("Fallo en conexión a base de datos: " . mysqli_error());
  32.  
  33. }
  34.  
  35. $ID = $_POST['p_ID'];
  36. $name = $_POST['p_Name'];
  37. $type = $_POST['p_Type'];
  38. $telephone = $_POST['p_Telephone'];
  39. $address = $_POST['p_Address'];
  40. $date = $_POST['p_Date'];
  41.  
  42. if ($ID == 0){
  43. $sql = "INSERT INTO `employee`(`name`, `type`, `telephone`, `address`, `employmentDate`) VALUES ('$name','$type','$telephone','$address','$date')";
  44. }
  45. else{
  46. $sql = "INSERT INTO `employee`(`name`, `type`, `telephone`, `address`, `employmentDate`) VALUES ('$name','$type','$telephone','$address','$date')";
  47. $sql = "UPDATE `employee` SET `name`='$name',`type`='$type',`telephone`='$telephone', `address`='$address', `employmentDate`='$date' WHERE `id_employee` = $id";
  48.  
  49. }
  50. $qry = mysqli_query($conn, $sql) or die('Consulta fallida');
  51.  
  52. if (!$qry) {
  53. die(mysqli_error());
  54.  
  55. }
  56. echo 'done';
  57. mysqli_close($conn);
  58. }
  59. else {
  60.  
  61. ?>
  62. <form method = "post" action = "<?php $_PHP_SELF; ?>">
  63. <table width = "400" border = "0" cellspacing = "1" cellpadding = "2">
  64. <tr>
  65. <td width = "100">ID (Leave blank if inserting)</td>
  66. <td><input name = "p_ID" type = "text" id = "post_ID"></td>
  67. </tr>
  68. <tr>
  69. <td width = "100">NAME</td>
  70. <td><input name = "p_Name" type = "text" id = "post_Name"></td>
  71. </tr>
  72. <tr>
  73. <td width = "100">TYPE</td>
  74. <td><input name = "p_Type" type = "text" id = "post_Type"></td>
  75. </tr>
  76. <tr>
  77. <td width = "100">Telephone</td>
  78. <td><input name = "p_Telephone" type = "text" id = "post_Telephone"></td>
  79. </tr>
  80. <tr>
  81. <td width = "100">Address</td>
  82. <td><input name = "p_Address" type = "text" id = "post_Address"></td>
  83. </tr>
  84. <tr>
  85. <td width = "100">Date</td>
  86. <td><input name = "p_Date" type = "text" value = "2018-03-09" id = "post_Date"></td>
  87. </tr>
  88. <tr>
  89. <td width = "100"> </td>
  90. <td> <input name = "update" type = "submit" id = "update" value = "update">
  91. </td>
  92. </tr>
  93. </table>
  94. </form>
  95.  
  96. <?php
  97. }
  98. ?>
  99. </body>
  100. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement