By clicking on my Ubmit, the php function is opening my file

Asked

Viewed 36 times

0

I have the following file called teste3.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 on Submit, this function is called in my.php register 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 on the Submit button, the.php register file opens and shows the following:

inserir a descrição da imagem aqui

  • Absolute certainty that PHP is installed on your machine?

  • yes, I use xampp, it installs php, I can also access phpmyadmin...

  • When I give php -v, PHP 7.2.10 is shown

  • is open with <?php

1 answer

0

The path specified in the address bar is from the file on the machine, so it does not run the file on the server.

You need to use the localhost path defined by xamp.

Example: localhost/cadastre.php

  • I switched to: <form action="127.0.0.1/cademeupet/cadastros.php" method="post"> but when I click on Ubmit, the.php entries file is still opened with the following content: query($sql); $bank->close(); header('Location: teste3.php'); } ?>

  • The action continues as entries.php. You will set the path in the browser as the localhost, as I have exemplified. Whenever the site is running on xampp vc runs on localhost.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.