Why is this error generated?

0

I'm trying to pass some values to php by means of jquery, but I get the following error:

llena.js:

window.onload = function() {
  var btnEnviar = document.getElementById("btn-enviar");
  btnEnviar.onclick = enviarForm;
  var cedula = document.getElementById("cedula");
  cedula.onblur = repetido;
  $.post("../php/llenar1.php", function(data) {
    $("#congregacion").html(data);
  });
}

function repetido() {
  var cedula = document.getElementById("cedula");
  var valor;
  valor = cedula.value;
  $.post("../php/repetido.php", {
    cedula: valor
  }, function(data) {
    if (data == valor) {
      alert("El usuario " + valor + " ya existe");
      cedula.value = "";
      cedula.focus = true;
    }
  });
}

function enviarForm() {
  var cedula = document.getElementById("cedula");
  var nombre = document.getElementById("nombre");
  var apellido = document.getElementById("apellido");
  var user = document.getElementById("user");
  var pwd = document.getElementById("pwd");
  var congregación = document.getElementById("congregacion");

  cedula.addEventListener('invalid', function(evt) {
    this.setCustomValidity('Por favor digite su numero de cedula');
  });
  cedula.addEventListener('input', function(evt) {
    this.setCustomValidity('');
  });

  nombre.addEventListener('input', function(evt) {
    this.setCustomValidity('');
  });
  nombre.addEventListener('invalid', function(evt) {
    this.setCustomValidity('Por favor digite su nombre');
  });

  apellido.addEventListener('input', function(evt) {
    this.setCustomValidity('');
  });
  apellido.addEventListener('invalid', function(evt) {
    this.setCustomValidity('Por favor digite su apellido');
  });

  user.addEventListener('input', function(evt) {
    this.setCustomValidity('');
  });
  user.addEventListener('invalid', function(evt) {
    this.setCustomValidity('Por favor digite su usuario');
  });

  pwd.addEventListener('input', function(evt) {
    this.setCustomValidity('');
  });
  pwd.addEventListener('invalid', function(evt) {
    this.setCustomValidity('Por favor digite su contraseña');
  });

  congregación.addEventListener('change', function(evt) {
    this.setCustomValidity('');
  });
  congregación.addEventListener('invalid', function(evt) {
    if (this.validity.valueMissing) {
      this.setCustomValidity('Por favor escoga una congregación');
    }
  });
  if (cedula.value != "" && nombre.value != "" && apellido.value != "" && user.value != "" && pwd.value != "" && congregación.value != "") {
    $.post("../php/reg_cap.php", {
      cedula: cedula,
      nombre: nombre,
      apellido: apellido,
      congregacion: congregacion,
      user: user,
      pwd: pwd
    });
  }
}
DOCTYPE html>
<html lang="es">

<head>
  <meta charset="UTF-8">
  <title>Formulario de registro</title>
  <link rel="stylesheet" href="../css/reg.css">
  <script src="../js/llenar.js"></script>
  <script src="../js/jquery-3.2.1.min.js"></script>
</head>

<body>
  <h1>Formulario de registro</h1>
  <form method="post" class="form-registro">
    <h2> Crear capitanes</h2>
    <div class="contenedor-input">
      <input type="number" id="cedula" name="cedula" placeholder="Cedula" class="input-100" required>
      <input type="text" id="nombre" name="nombre" placeholder="Nombres" class="input-48" required>
      <input type="text" id="apellido" name="apellido" placeholder="Apellidos" class="input-48" required>
      <input type="text" id="user" name="user" placeholder="Usuario" class="input-48" required>
      <input type="text" id="pwd" name="pwd" placeholder="Contraseña" class="input-48" required>
      <select name="congregacion" id="congregacion" class="input-100" required>
			</select>
      <input type="submit" value=" Registrar capitan" class="btn-enviar" id="btn-enviar">
    </div>
  </form>
</body>

</html>

This is the PHP

?php
include ("conex.php");
$cedula = $nombre = $apellido = $cmbCongregacion = $user = $pwd = "";
if ($_SERVER["REQUEST_METHOD"] == "POST"){
    $cedula = mysqli_real_escape_string($con,$_POST['cedula']);
    $nombre = mysqli_real_escape_string($con,$_POST['nombre']);
    $apellido = mysqli_real_escape_string($con,$_POST['apellido']);
    $congregacion = mysqli_real_escape_string($con,$_POST['cmbcongregacion']);
    $user = mysqli_real_escape_string($con,$_POST['user']);
    $pwd = mysqli_real_escape_string($con,$_POST['pwd']);
    $sql = "INSERT INTO hermanos (cedula, nombre, apellido) VALUES ('$cedula', '$nombre', '$apellido')";
    mysqli_query($con, $sql);
    $sql = "INSERT INTO hermano_congregacion (cod_congregacion, cedula, user, pwd) VALUES ('$congregacion', '$cedula', '$user', '$pwd')";
    mysqli_query($con, $sql);
    mysqli_close( $con);    
}   
?>

the data is not recorded in the database, but it takes a long time to do the process and then I throw out the error that can be seen in the image.

I appreciate your help

    
asked by Familia Valencia Hdz 30.12.2017 в 01:52
source

1 answer

0

This error was presented because it does not assign any value to the variables that receive the html objects

    
answered by 31.12.2017 / 06:53
source