Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <!--
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
- -->
- <html>
- <head>
- <meta charset="UTF-8">
- <title></title>
- </head>
- <body>
- <?php
- if (isset($_POST['update'])) {
- $dbhost = '127.0.0.1';
- $dbuser = 'root';
- $dbpass = '';
- $db = 'lala';
- $conn = mysqli_connect($dbhost, $dbuser, $dbpass);
- if (!$conn) {
- die("Fallo en conexión: " . mysqli_error());
- }
- $db_select = mysqli_select_db($conn, $db);
- if (!$db_select) {
- die("Fallo en conexión a base de datos: " . mysqli_error());
- }
- $ID = $_POST['p_ID'];
- $name = $_POST['p_Name'];
- $type = $_POST['p_Type'];
- $telephone = $_POST['p_Telephone'];
- $address = $_POST['p_Address'];
- $date = $_POST['p_Date'];
- if ($ID == null){
- $sql = "INSERT INTO `employee`(`name`, `type`, `telephone`, `address`, `employmentDate`) VALUES ('$name','$type','$telephone','$address','$date')";
- }
- else{
- $sql = "UPDATE `employee` SET `name`='$name',`type`='$type',`telephone`='$telephone', `address`='$address', `employmentDate`='$date' WHERE `id_employee` = $ID";
- }
- $qry = mysqli_query($conn, $sql) or die('Consulta fallida');
- if (!$qry) {
- die(mysqli_error());
- }
- echo 'done';
- mysqli_close($conn);
- }
- else {
- ?>
- <form method = "post" action = "<?php $_PHP_SELF; ?>">
- <table width = "400" border = "0" cellspacing = "1" cellpadding = "2">
- <tr>
- <td width = "100">ID (Leave blank if inserting)</td>
- <td><input name = "p_ID" type = "text" id = "post_ID"></td>
- </tr>
- <tr>
- <td width = "100">NAME</td>
- <td><input name = "p_Name" type = "text" id = "post_Name"></td>
- </tr>
- <tr>
- <td width = "100">TYPE</td>
- <td><input name = "p_Type" type = "text" id = "post_Type"></td>
- </tr>
- <tr>
- <td width = "100">Telephone</td>
- <td><input name = "p_Telephone" type = "text" id = "post_Telephone"></td>
- </tr>
- <tr>
- <td width = "100">Address</td>
- <td><input name = "p_Address" type = "text" id = "post_Address"></td>
- </tr>
- <tr>
- <td width = "100">Date</td>
- <td><input name = "p_Date" type = "text" value = "2018-03-09" id = "post_Date"></td>
- </tr>
- <tr>
- <td width = "100"> </td>
- <td> <input name = "update" type = "submit" id = "update" value = "add/update">
- </td>
- </tr>
- </table>
- </form>
- <?php
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement