I have the following data logging system, although it seems that everything works fine, do not insert the data in the database:
Conexion.php
$cone = new mysqli($host,$usua,$pass,$base);
if ($cone->connect_errno) {
echo "Falló la conexión a MySQL: (" . $cone->connect_errno . ") " . $cone->connect_error;
}
?>
Registrar.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title> </title>
</head>
<body>
<h1 align ="center">Bienvenido</h1>
<a href ="index.html"><ol>Pagina Principal</ol></a>
<a href ="registrar.php"><ol>Registrar</ol></a>
<a href ="listado.php"><ol>Listado</ol></a>
<a href ="Sancion.php"><ol>Sancion</ol></a>
<form method="POST" action ="procesar.php">
<label> Ingrese su nombre </label>
<input type="text" name="nombre"><br/>
<label> Ingrese su apellido </label>
<input type="text" name="apellido"><br/>
<label> Ingrese su cedula </label>
<input type="text" name="cedula"><br/>
<label> Ingrese su rango </label>
<div><select name="rango">
</select></div>
<?php
include "conexion.php";
global $cone;
$registros=mysqli_query($cone,"select * from rangos");
while ($reg = mysqli_fetch_array($registros))
echo '<option value="'.$reg[id_rango].'">'.$reg[rango].'</option>';
?>
<input type="submit" value="enviar">
</form>
</body>
</html>
Process.php
<?php
require_once'conexion.php';
include'funciones.php';
bd_agregar($_REQUEST);
?>
<html>
<a href="index.html"> VOLVER </a>
</html>
Functions.php
<?php
require_once'conexion.php';
//Creamos función
function bd_agregar($d){
//Especificamos variable global.
global $cone;
//Obtenemos datos formulario
$nombre = $_POST['nombre'];
$apellido = $_POST['apellido'];
$cedula = $_POST['cedula'];
$rango = $_POST['rango'];
//Insertamos datos
$cone->query("INSERT INTO personal(nombre,apellido,cedula,rango_id) VALUES ('$nombre','$apellido','$cedula','$rango')");
echo $nombre.$apellido.$cedula.$rango;
//Comprobamos ejecución sentencia.
if ($cone===false) {
printf("Mensaje de error: %s\n", $cone->error);
} else {
echo "Los datos se insertaron correctamente";
$cone->close();
} ? >
I hope your help:)
ERROR:
The system displays the message "Data was inserted correctly", but does not insert anything in the database
I found the error. It happens that the value "RANK" does not save anything and therefore the query does not pass
Use this code to display data that is in a BD.
global $cone;
$registros=mysqli_query($cone,"select * from rangos");
while ($reg = mysqli_fetch_array($registros))
echo "<option value='"$reg[id_rango]"'>".$reg[rango]."</option>";
and the Value does not pass, as you could solve it