code of the PHP page appearing when clicking the Submit button of the form

Asked

Viewed 674 times

2

On my html page I have the following form:

<form method="POST" action="index.php" class="header">
    
    <label for="km_tdo" id="lbTdo">KM troca de óleo:</label><input class="text-input" type="text" name="km_tdo" id="km_tdo" autofocus data-rule-required="true"/><button type="button" onclick="estadoAtual()">Ok</button><div class="situacao km_trocadeoleo" id="km_trocadeoleo"></div><br>
    
    <label for="km_alin" id="lbAlinhamento">KM alinhamento:</label><input class="text-input" type="text" name="km_alin" id="km_alin" data-rule-required="true"/><button type="button" onclick="estadoAtualAlinhamento()">Ok</button><div class="situacao km_alinhamento" id="km_alinhamento"></div><br>
    
    <label for="revisao" id="lbRevisao">Revisão:</label><input class="text-input" type="text" name="revisao" id="revisao" data-rule-required="true"/><button type="button" onclick="estadoAtualRevisao()">Ok</button><div class="situacao result_revisao" id="km_revisao"><br>
    </div><br>
    
    <label for="last_km_abastecimento" id="lbKmAbastecimento">KM do abastec..:</label><input class="text-input" type="text" name="last_km_abastecimento" id="last_km_abastecimento" data-rule-required="true"/>
    
    <label for="dt_lancamento_combustivel" id="lbDataAbastecimento">Data abastec..:</label><input type="date" class="text-input text-input-data" name="dt_lancamento_combustivel" id="dt_lancamento_combustivel"><br>
    
    <label for="placa_do_veiculo" id="lbPlacaVeiculo">Placa:</label>
    <select name="placa_do_veiculo" id="placa_do_veiculo">
      <option value="MSS-1370">MSS-1370</option>
      <option value="MPK-6473">MPK-6473</option>
      <option value="MTO-1121">MTO-1121</option>
    </select>
    <label for="tipo_de_servico" id="lbTipoServico">Serviço:</label>
    <select name="tipo_de_servico" id="tipo_de_servico" class="list-menu">
      <option value="1">Abastecimento</option>
      <option value="2">Alinhamento</option>
      <option value="3">Revisão</option>
      <option value="4">Troca de óleo</option>
    </select>
    <button type="submit" class="btn_gravar_dados btn_azul">Registrar</button>
  </form> 

After clicking the register button a page is loaded (on the same tab) displaying the contents of my index.php, this one:

<?php
  include("conexao.php");

  $km_troca_de_oleo = $_POST['km_tdo'];
  $km_alinhamento = $_POST['km_alin'];
  $km_revisao = $_POST['revisao'];
  $km_abastecimento = $_POST['last_km_abastecimento'];
  $data_abastecimento = $_POST['dt_lancamento_combustivel'];
  $placa = $_POST['placa_do_veiculo'];
  $tipo_de_servico = $_POST['tipo_de_servico'];

  // criando conexão
  $conn = new mysqli($servername, $username, $password, $dbname);

  // checando conexão
  if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
  } 

  //string de inserção
  $sqlInsertInto = "INSERT INTO veiculo (placa, km_abastecimento, data_abastecimento, km_troca_de_oleo, km_alinhamento, km_revisao)
   VALUES ('$placa','$km_abastecimento','$data_abastecimento','$km_troca_de_oleo','$km_alinhamento','$km_revisao')";

  //verifico se houve sucesso na tentativa de persistir os dados no banco
  if ($conn->query($sqlInsertInto) === TRUE) {
    echo "Dados cadastrados com sucesso!";
  } else {
    echo "Error: " . $sql . "<br>" . $conn->error;
  }

  //encerro a conexão com o banco de dados
  $conn->close();
?>

content of my connection.php file:

<?php
  $servername = "localhost";
  $username = "root";
  $password = " ";
  $dbname = "controle_de_tipo_de_servico_do_veiculo";

  $conn = mysqli_connect($servername, $username, $password, $dbname);
?> 

I’ve been told it could be the server-related service, but I’m using XAMPP and it went up, because I have phpmyadmim open.

  • apache ta running in XAMPP? The address in the browser bar ta as localhost?

  • Maybe your Apache isn’t activated...

  • @Lindomar yes on XAMPP, yes localhost!

  • @Yesterday Angelosoares was working normally, today is giving this problem. I put to create shortcut on desktop when I installed XAMPP, but did not create, I searched for it in all programs (using windows 7) it also does not appear. Today more sedo to access the phpmyadmin I had to go in the folder xampp saved in the root directory and startar there, the apache startei also there (I’m open in the prompt window)

4 answers

4

It is possible that you are opening the . html file instead of using the localhost. Be sure to use the path localhost/[nome da pasta]/[nome do arquivo].html in your browser

2

I solved the problem! I will answer here to leave registered and that new users with similar problems can test this hypothesis.

The problem is in the file .php(file name "index.php") which is called at the press of the register button.

I’m using the wamp and by default(apparently, I’m not sure!) the upload of the files that is in the folder www(localhost) carries the index.php first. Accessing by localhost/index.html the front of the application was presented normally.

So I changed the name of the file index.php to another name and deleted the name "index.php" in action of form and replaced by the new file name. Ex.: "cadastradados.php".

I removed the line referring to the creation of the connection (because it is already contained in the file conexao.php) of arquivo.php(what we changed the name, the old "index.php") which is called after the user click the register button.

  • So when you said that "php page code" appeared after sending the form was the result of processing that code, not the source code?

  • was the source code!

  • But if it does not process index.php, it should not process registered.php. What you should do is process any php, regardless of the file name. The source of your problem must be somewhere else.

0

Good day, There may be several reasons why this is happening among them :

  • Failed to start PHP server
  • File renamed wrong ex: "index.php.html" looks like a joke but happens a lot.
  • Special character in the middle of typing the PHP code, sometimes gave a CTRL + V and accidentally came along.
  • Apache with disfigured rewrite.

Some I can remember now.

  • how do I check this last item from the list?

  • This link will give you a direction. https://www.digitalocean.com/community/tutorials/como-installr-a-pilha-linux-apache-mysql-php-lamp-no-ubuntu-18-04-pt , already give a general on your server and see if the settings are like this.

  • Stay tuned to the programs installed on your machine for example SKYPE, which uses the same port of xampp and ends up preventing the functioning of it if it is running.

0

With database I never did, but I made a form with sending email, and I used Ajax because of the redirection of the page I did not want, and I had this problem sending that showed what was happening on the server and loading the page. In my case in the file send php. I put this -> $mail->SMTPDebug = 0;. Maybe this will help you.

  • 1

    I already did, but thanks for your help!

Browser other questions tagged

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