I need your help, I have a PHP form, which in an HTML select I get data from a table, the data I get is PK from another table (FK), then enter them into the database, the problem is that when I click the enter button, this data is not entered into the database and I do not even get an error, I do not know what I'm doing wrong, or maybe I can not add a data that is already added in the bd ?, I'll leave the code PHP and HTML, please your comments:
<?php
include "../conexionBD.php";
if ($op == "add"){
//asigna el post a las variables
$Numero = $_POST['Numero'];
$Sector = $_POST['ListaSector'];
$Capacidad = $_POST['Capacidad'];
$Listagarzon = $_POST['Listagarzon'];
//prepara la query
$stmt = $bd->prepare("
INSERT INTO mesa (Numero, Sector, Capacidad, Rut_garzon)
VALUES (?, ?, ?, ?)");
//asigna las variables a la query
$stmt->bind_param('isis', $Numero, $Sector, $Capacidad, $Listagarzon);
//ejecuta la query
$stmt->execute();
}
header('Location: modmesas.php');
?>
<section>
<div class="container">
<h4 align="center">Ingresar mesa</h4>
<form action="controladorMesas.php?op=add" method="POST" enctype="multipart/form-data">
<div class="form-group">
<label for="Numero">Número:</label>
<input type="number" step="1" class="form-control" id="Numero" name="Numero" min="1" max="20" placeholder="Ingresar número de mesa">
</div>
<div class="form-group">
<label for="Sector">Sector:</label>
<select class="form-control" id="sel2" name="ListaSector">
<option value="Primer piso">Primer piso</option>
<option value="Segundo piso">Segundo piso</option>
</select>
</div>
<div class="form-group">
<label for="Capacidad">Capacidad:</label>
<input type="number" step="1" class="form-control" id="Capacidad" name="Capacidad" min="2" max="6" placeholder="Ingresar capacidad de personas">
</div>
<div class="form-group">
<label for="Garzon">Garzon:</label>
<?php echo '<select class="form-control" id="sel3" name="Listagarzon">
<option>Seleccione:</option>'?>
<?php
include "../conexionBD.php"; // este esta de más, ya estas llamando la conexion arriba
$query = 'SELECT * FROM garzon';
$result = $bd->query($query);
while ( $row = $result->fetch_array() )
{
?>
<option value=" <?php echo $row['Rut'] //el echo no esta cerrado ?> " >
<?php echo $row['Rut']; ?>
</option>
<?php
}
?>
</select>
<?php
// para que esta este PHP?
?>
</div>
<div class="btn-lg">
<button type="submit" class="btn btn-primary" onclick="agregar()">Agregar</button>
</div>
</form>