form does not insert into the database

2

I have a HTML with this 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 stores in bd. with this 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 submit instead of inserting and returning to the index, the code

    
asked by anonymous 09.07.2015 / 11:50

1 answer

3

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

    
09.07.2015 / 12:36