I have the following file called test3.php:
<form action="cadastros.php" method="post">
<label for="latitude" hidden>Latitude:</label>
<input id="latMap" hidden name="latitude"/>
<label for="longitude" hidden>Longitude:</label>
<input id="lngMap" hidden name="longitude"/>
<input type="hidden" name="acao" value="inserir">
<input type="submit">
</form>
When I click submit, this function is called in my cadastros.php file:
if(isset($_POST['acao'])){
if($_POST['acao'] == "inserir"){
cadastraLatLong();
}
}
function abrirBanco(){
$conexao = new mysqli("localhost", "root", "", "cademeupet");
return $conexao;
}
function cadastraLatLong(){
$latitude = $_POST['latitude'];
$longitude = $_POST['longitude'];
$banco = abrirBanco();
$sql = "INSERT INTO marcadores (id, descricao, lat, lng, tipo) VALUES (NULL, 'teste', '$latitude', '$longitude', 'testetipo')";
$banco->query($sql);
$banco->close();
header('Location: teste3.php');
}
When I click the submit button, the cadastros.php file opens and displays the following: