form does not insert into database

Asked

Viewed 50 times

2

I have a HTML with that code:

<div class="row">
 <form method="post" action="php/mensagem.php"  accept-charset="utf-8"> 
  <div class="row">
   <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<input class="col-lg-12 col-md-12 col-sm-12 col-xs-12" name="nome" placeholder="Nome" type="text" required> 
<input class="col-lg-12 col-md-12 col-sm-12 col-xs-12" name="email" placeholder="E-mail" type="email" required>
<input class="col-lg-12 col-md-12 col-sm-12 col-xs-12" name="telefone" placeholder="Telefone" type="text" maxlength="9" required> 
   </div>
   <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12"> 
<textarea class="input-xlarge col-lg-12 col-md-12 col-sm-12 col-xs-12" id="message" name="mensagem" placeholder="Mensagem" rows="6" required>            </textarea>
   </div>
   <div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
 <button class="btn btn-primary" type="reset" style="float:left;">Apagar</button>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
 <input type="submit" class="btn btn-primary" value="Enviar" style="margin-top:-39px; float:right"/>
</div>
   </div>
  </div>
 </form>
</div>

that sends to PHP that you keep in your comic book. with that code:

<php>
  
  $con = mysqli_connect("localhost","root","","saber");
  
  $nome = $_POST['nome'];
  $mail = $_POST['email'];
  $tlm = $_POST['telefone'];
  $msn = $_POST['mensagem'];
  $vista = 0;
  
  $sql = "insert into mensagem(nome,mail,telefone,mensagem,vista) values ('$nome','$mail','$tlm','$msn',$vista)";
  
  if(mysqli_query($con, $sql)){
    echo "<script>
            alert('Mensagem enviada');
            document.location.href = 'index.html';
          </script>";
  }
  else{
    echo "<script>
            alert('Mensagem não enviada');
            document.location.href = 'index.html';
          </script>";
  }
  
?>

And when I click on Submit instead of inserting and returning to the index only appears the code

  • And what appears from the Alert?

  • nothing appears only php code

1 answer

3


You are probably accessing the . html page that has the form using the protocol file:/// you must access it by localhost so the code of the file . php will be executed.

  • How stupid I was! I’m even ashamed to have asked this question! You’re absolutely right

  • 1

    don’t need to ask already gave and gladly

Browser other questions tagged

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