Advertisement
Guest User

Untitled

a guest
Jul 14th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. xmlhttp=new XMLHttpRequest();
  2.  
  3. <form id="formulario" action="" method="POST">
  4. <div class="form-group">
  5. <label for="idnombre">Nombre:</label>
  6. <input type="text" class="form-control" id="idnombre" name="namenombre" placeholder="Ingresar Nombre">
  7. </div>
  8.  
  9. <div class="form-group">
  10. <label for="idapellido">Apellido:</label>
  11. <input type="text" class="form-control" id="idapellido" name="nameapellido" placeholder="Ingresar Apellido">
  12. </div>
  13.  
  14. <div class="form-group">
  15. <label for="idedad">Edad:</label>
  16. <input type="text" class="form-control" id="idedad" name="nameedad" placeholder="Ingresar Edad">
  17. </div>
  18.  
  19. <button type="submit" id="button" class="btn btn-default">Registrar</button>
  20. </form>
  21.  
  22. <?php
  23. $servername = "localhost";
  24. $username = "username";
  25. $password = "";
  26. $dbname = "demo";
  27.  
  28. // Create connection
  29. $conn = new mysqli($servername, $username, $password, $dbname);
  30. // Check connection
  31. if ($conn->connect_error) {
  32. die("Connection failed: " . $conn->connect_error);
  33. }
  34.  
  35. $nombre = $_POST['namenombre'];
  36. $apellido = $_POST['nameapellido'];
  37. $edad = $_POST['nameedad'];
  38.  
  39.  
  40. $sql = "INSERT INTO persona (nombre, apellido, edad) VALUES ('$nombre', '$apellido', '$edad')";
  41.  
  42. if ($conn->query($sql) === TRUE) {
  43. echo "New record created successfully";
  44. } else {
  45. echo "Error: " . $sql . "<br>" . $conn->error;
  46. }
  47.  
  48. $conn->close();
  49.  
  50. ?>
  51.  
  52. <div class="alert alert-success">
  53. <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
  54. <strong>Success!</strong> This alert box could indicate a successful or positive action.
  55. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement