I have the following code:
$cantidadcupos=$_POST['cantidad_cupos'];
$idparking=$_POST['idestacionamiento'];
for($i=0; $i<=count($cantidadcupos) ;$i++){
$query="INSERT INTO cupos(numero, estado, reserva_id_reserva, estacionamiento_id_estacionamiento)
VALUES ('1','disponible','1','1111')";
}
try {
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
} catch (PDOException $ex) {
$response["success"] = 0;
$response["message"] = "Error base de datos2. Porfavor vuelve a intentarlo";
die(json_encode($response));
}
$response["success"] = 1;
$response["message"] = "El cupo se ha agregado correctamente";
echo json_encode($response);
The variable $cantidad_cupos
receives a number, and according to that number I need to make the insertions in the bd, eg: cantidad_cupos=20
and make 20 records, but with the code that I have I can not do that, I think I'm missing a transformation of the variable or something like that, but I can not find the answer.