Advertisement
Guest User

Untitled

a guest
Apr 5th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.63 KB | None | 0 0
  1. <?php
  2.  
  3. $aErrores = array();
  4. if((isset($_POST["adminName"]))&&($_POST["adminName"]!="")){ $nameAdmin=$_POST["adminName"]; } else {$aErrores[] = "Debe especificar el nombre del admin";}
  5. if((isset($_POST["adminLastname"]))&&($_POST["adminLastname"]!="")){ $adminLastname=$_POST["adminLastname"]; } else { $aErrores[] = "Debe especificar el apellido del admin";}
  6. if((isset($_POST["entityName"]))&&($_POST["entityName"]!="")){ $entityName=$_POST["entityName"]; } else {$aErrores[] = "Debe especificar el nombre de la entidad";}
  7. if((isset($_POST["country"]))&&($_POST["country"]!="")){ $country=$_POST["country"]; } else {$aErrores[] = "Debe especificar la localización de la entidad";}
  8. if((isset($_POST["address"]))&&($_POST["address"]!="")){ $address=$_POST["address"]; } else {$aErrores[] = "Debe especificar la dirección de la entidad";}
  9. if((isset($_POST["entityTypeSpeciality"]))&&($_POST["entityTypeSpeciality"]!="")){ $entityTypeSpeciality=$_POST["entityTypeSpeciality"]; } else {$aErrores[] = "Debe especificar el tipo de especilidad";}
  10. if((isset($_POST["entitySpeciality"]))&&($_POST["entitySpeciality"]!="")){ $entitySpeciality=$_POST["entitySpeciality"]; } else {$aErrores[] = "Debe especificar el nombre de la especialidad";}
  11. if((isset($_POST["phone"]))&&($_POST["phone"]!="")){ $phone=$_POST["phone"]; } else {$aErrores[] = "Debe especificar el número de teléfono";}
  12.  
  13.  
  14.  
  15. //Datos de Conexión de Base de datos BD_01
  16. $dbserver = "localhost";
  17. $dbuser = "root";
  18. $password = "123456";
  19. $dbname = "BD_01";
  20.  
  21. $database = new mysqli($dbserver, $dbuser, $password, $dbname);
  22.  
  23. if($database->connect_errno) {
  24.   die("No se pudo conectar a la base de datos");
  25. }
  26.  
  27. $jsondata = array();
  28.  
  29.  
  30. if(count($aErrores)==0) {
  31.  
  32.   if ( $result = $database->query( "INSERT INTO `BD_01`.`m_entidad` (`m_entidad_id`, `m_entidad_adminName`, `m_entidad_ddminLastName`, `m_entidad_name`, `m_entidad_location`, `m_entidad_address`, `m_entidad_type`, `m_entidad_specialty`, `m_entidad_phone`) VALUES (NULL, '$adminName', '$adminLastname', '$entityName', '$country', '$address', '$entityTypeSpeciality', '$entitySpeciality', '$phone'); " ) ) {
  33.  
  34.     if( $result ) {
  35.       $jsondata["success"] = true;
  36.       $jsondata["data"]["message"] = sprintf("La entidad se ha registrado exitosamente");
  37.      
  38.     }
  39.  
  40.   } else {
  41.  
  42.    $jsondata["success"] = false;
  43.    $jsondata["data"] = array(
  44.      'message' => 'Error al intentar guardar'
  45.      );
  46.  
  47.  }
  48.  
  49.  
  50. }else{
  51.   $jsondata["success"] = false;
  52.   $jsondata["data"]["message"] = $aErrores;  
  53.  
  54.  
  55.   header('Content-type: application/json; charset=utf-8');
  56.   echo json_encode($jsondata, JSON_FORCE_OBJECT);
  57.  
  58.   $database->close();
  59.  
  60. }
  61.  
  62. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement