The database 5 tables: client, room, history, staff and user.
In the user table is the ID which also happens for the room as user_id, I make my normal form and it appears that the room has been created, but it does not show it or save it, from the database if I can insert data.
It does not throw me any error, it just does not save in the database, I think it's because of the ID relationship with user_id but I do not know what to do.
Edited: It is assumed that the ID of the user table given to me should be assigned to the one in the room.
User table:
CREATE TABLE 'usuario' (
'id' int(11) NOT NULL,
'usuario' varchar(20) NOT NULL,
'clave' varchar(150) NOT NULL,
'rango' varchar(20) NOT NULL,
'cedula' int(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Volcado de datos para la tabla 'usuario'
--
INSERT INTO 'usuario' ('id', 'usuario', 'clave', 'rango', 'cedula') VALUES
(1, 'eduardo', 'eduardo', '1', 262944),
(18, 'EduardoJ', '123456', '1', 262);
Room table:
CREATE TABLE 'habitacion' (
'id' int(11) NOT NULL,
'estado' varchar(200) NOT NULL,
'n_habitacion' varchar(200) NOT NULL,
'tipoh' varchar(200) NOT NULL,
'id_usuario' int(200) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Volcado de datos para la tabla 'habitacion'
--
INSERT INTO 'habitacion' ('id', 'estado', 'n_habitacion', 'tipoh', 'id_usuario') VALUES
(10, 'Ocupado', '1', 'Completa', 18);
My code is this.
HTML:
<form action="validarhabitacion.php" method="POST">
<table style="margin: 0 auto;">
<tr>
<td colspan="2"><CENTER><h2>Crear Habitación<h2></CENTER></td>
</tr>
<tr>
<td><h3>Estado de Habitación<h3></td></font>
<td><input name="estado" type="text" placeholder="" required></td>
</tr>
<tr>
<tr>
<td><h3>Número de Habitación<h3></td>
<td><input name="n_habitacion" type="text" placeholder="" required></td>
</tr>
<tr>
<td><h3>Tipo de Habitación<h3></td></font>
<td><input name="tipoh" type="text" placeholder=""required></td>
</tr>
<td colspan="2">
<center><input type="submit" value="Crear"></center>
</td>
</table>
</form>
PHP file validatinghabitation.php:
<?php
$estado=$_POST['estado'];
$n_habitacion=$_POST['n_habitacion'];
$tipoh= $_POST['tipoh'];
require("connect_db.php");
mysqli_query($mysqli,"INSERT INTO habitacion VALUES('','$estado','$n_habitacion','$tipoh')");
//echo 'Se ha registrado con exito';
echo ' <script language="javascript">alert("Habitación Creada");</script> ';
echo "<script>location.href='controlhabitacion.php'</script>";
?>
Connection to database:
<?php
$mysqli = new MySQLi("localhost", "root","", "aeduardo");
if ($mysqli -> connect_errno) {
die( "Fallo la conexión a MySQL: (" . $mysqli -> mysqli_connect_errno()
. ") " . $mysqli -> mysqli_connect_error());
}
else
?>