Advertisement
Guest User

Untitled

a guest
Mar 9th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 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 == null){
  43. $sql = "INSERT INTO `employee`(`name`, `type`, `telephone`, `address`, `employmentDate`) VALUES ('$name','$type','$telephone','$address','$date')";
  44. }
  45. else{
  46. $sql = "UPDATE `employee` SET `name`='$name',`type`='$type',`telephone`='$telephone', `address`='$address', `employmentDate`=$date WHERE `id_employee` = $ID";
  47.  
  48. }
  49. $qry = mysqli_query($conn, $sql) or die('Consulta fallida');
  50.  
  51. if (!$qry) {
  52. die(mysqli_error());
  53.  
  54. }
  55. echo 'done';
  56. mysqli_close($conn);
  57. }
  58. else {
  59.  
  60. ?>
  61. <form method = "post" action = "<?php $_PHP_SELF; ?>">
  62. <table width = "400" border = "0" cellspacing = "1" cellpadding = "2">
  63. <tr>
  64. <td width = "100">ID (Leave blank if inserting)</td>
  65. <td><input name = "p_ID" type = "text" id = "post_ID"></td>
  66. </tr>
  67. <tr>
  68. <td width = "100">NAME</td>
  69. <td><input name = "p_Name" type = "text" id = "post_Name"></td>
  70. </tr>
  71. <tr>
  72. <td width = "100">TYPE</td>
  73. <td><input name = "p_Type" type = "text" id = "post_Type"></td>
  74. </tr>
  75. <tr>
  76. <td width = "100">Telephone</td>
  77. <td><input name = "p_Telephone" type = "text" id = "post_Telephone"></td>
  78. </tr>
  79. <tr>
  80. <td width = "100">Address</td>
  81. <td><input name = "p_Address" type = "text" id = "post_Address"></td>
  82. </tr>
  83. <tr>
  84. <td width = "100">Date</td>
  85. <td><input name = "p_Date" type = "text" value = "2018-03-09" id = "post_Date"></td>
  86. </tr>
  87. <tr>
  88. <td width = "100"> </td>
  89. <td> <input name = "update" type = "submit" id = "update" value = "update">
  90. </td>
  91. </tr>
  92. </table>
  93. </form>
  94.  
  95. <?php
  96. }
  97. ?>
  98. </body>
  99. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement