Advertisement
Guest User

Untitled

a guest
Sep 27th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";
  3. $username = "root";
  4. $password = "";
  5. $db = "data_estudiantes";
  6.  
  7. // Create connection
  8. $conn = new mysqli($servername, $username, $password, $db);
  9.  
  10. // Check connection
  11. if ($conn->connect_errno) {
  12. die("Connection failed: " . mysqli_connect_error());
  13. }
  14.  
  15. $nombre = $_POST['nombre'];
  16. $apellidos = $_POST['apellidos'];
  17. $cedula = $_POST['cedula'];
  18.  
  19. $sql = "insert into estudiantes (nombre, apellidos, cedula) VALUES ('$nombre', '$apellidos', '$cedula')";
  20. $resultado = $conn->query($sql);
  21. $id = $conn->insert_id;
  22. echo json_encode(array('id'=>$id, 'nombre' => $nombre, 'apellidos' => $apellidos, 'cedula' => $cedula));
  23. ?>
  24.  
  25. $.ajax({
  26. url: 'addEstudent.php',
  27. type: 'POST',
  28. data: {nombre: nombre, apellidos:apellido, cedula:cedula},
  29. success:function(data){
  30. console.log(data);
  31. var fila = '<tr id="'+data['id']+'"><td>'+ data['nombre'] +'</td><td>'+ data['apellidos'] +'</td><td>'+data['cedula']+'</td><td><button class="btn btn-danger eliminarBtn" data-idest = "'+value['id']+'"><i class="glyphicon glyphicon-remove"></i></button></td></tr>';
  32. $('tbody').append(fila);
  33. $('#contador').html($('tbody tr').length);
  34. },
  35. dataType: 'json',
  36. });
  37. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement