Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. $cone = new mysqli($host,$usua,$pass,$base);
  2.  
  3. if ($cone->connect_errno) {
  4. echo "Falló la conexión a MySQL: (" . $cone->connect_errno . ") " . $cone->connect_error;
  5. }
  6. ?>
  7.  
  8. <!doctype html>
  9. <html>
  10. <head>
  11. <meta charset="utf-8">
  12. <title> </title>
  13. </head>
  14. <body>
  15. <h1 align ="center">Bienvenido</h1>
  16. <a href ="index.html"><ol>Pagina Principal</ol></a>
  17. <a href ="registrar.php"><ol>Registrar</ol></a>
  18. <a href ="listado.php"><ol>Listado</ol></a>
  19. <a href ="Sancion.php"><ol>Sancion</ol></a>
  20. <form method="POST" action ="procesar.php">
  21. <label> Ingrese su nombre </label>
  22. <input type="text" name="nombre"><br/>
  23.  
  24. <label> Ingrese su apellido </label>
  25. <input type="text" name="apellido"><br/>
  26.  
  27. <label> Ingrese su cedula </label>
  28. <input type="text" name="cedula"><br/>
  29.  
  30. <label> Ingrese su rango </label>
  31. <div><select name="rango">
  32. </select></div>
  33. <?php
  34. include "conexion.php";
  35. global $cone;
  36. $registros=mysqli_query($cone,"select * from rangos");
  37. while ($reg = mysqli_fetch_array($registros))
  38. echo '<option value="'.$reg[id_rango].'">'.$reg[rango].'</option>';
  39. ?>
  40.  
  41. <input type="submit" value="enviar">
  42. </form>
  43.  
  44. </body>
  45. </html>
  46.  
  47. <?php
  48. require_once'conexion.php';
  49. include'funciones.php';
  50.  
  51. bd_agregar($_REQUEST);
  52.  
  53. ?>
  54.  
  55. <html>
  56. <a href="index.html"> VOLVER </a>
  57. </html>
  58.  
  59. <?php
  60. require_once'conexion.php';
  61.  
  62. //Creamos función
  63. function bd_agregar($d){
  64. //Especificamos variable global.
  65. global $cone;
  66.  
  67. //Obtenemos datos formulario
  68. $nombre = $_POST['nombre'];
  69. $apellido = $_POST['apellido'];
  70. $cedula = $_POST['cedula'];
  71. $rango = $_POST['rango'];
  72.  
  73. //Insertamos datos
  74. $cone->query("INSERT INTO personal(nombre,apellido,cedula,rango_id) VALUES ('$nombre','$apellido','$cedula','$rango')");
  75. echo $nombre.$apellido.$cedula.$rango;
  76.  
  77.  
  78. //Comprobamos ejecución sentencia.
  79. if ($cone===false) {
  80. printf("Mensaje de error: %sn", $cone->error);
  81. } else {
  82. echo "Los datos se insertaron correctamente";
  83.  
  84. $cone->close();
  85.  
  86. global $cone;
  87. $registros=mysqli_query($cone,"select * from rangos");
  88. while ($reg = mysqli_fetch_array($registros))
  89. echo "<option value='"$reg[id_rango]"'>".$reg[rango]."</option>";
  90.  
  91. echo "<option value='$reg[id_rango]'>".$reg[rango]."</option>";
  92.  
  93. <?php
  94. require_once'conexion.php';
  95.  
  96. //Creamos función
  97. function bd_agregar($d){
  98. //Especificamos variable global.
  99. global $cone;
  100.  
  101. //Obtenemos datos formulario
  102. $nombre = $_POST['nombre'];
  103. $apellido = $_POST['apellido'];
  104. $cedula = $_POST['cedula'];
  105. $rango = $_POST['rango'];
  106. echo $nombre."<br/>".$apellido."<br/>".$cedula."<br/>".$rango."<br/>";
  107. //Insertamos datos
  108. $cone->query("INSERT INTO personal (nombre,apellido,cedula,rango_id) VALUES('$nombre','$apellido','$cedula','$rango')");
  109.  
  110.  
  111.  
  112. //Comprobamos ejecución sentencia.
  113. if ($cone===false) {
  114. printf("Mensaje de error: %sn", $cone->error);
  115. } else {
  116. echo "Los datos se insertaron correctamente";
  117. }
  118. $cone->close();
  119. }
  120. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement