我的代码不保存数据表单

时间:2016-10-06 14:36:52

标签: php mysql mysqli

我在将数据写入带有表单的页面时遇到问题。下面是它的外观,然后是我正在使用的一些代码:

enter image description here

    <section>
      <form method="POST" action="/teste/registro.php">
       <div class="container"> 
          <div class="form-group">
           <label for="nome">Nome</label>
           <input type="text" name="nome" id="nome" placeholder="nome completo"class="form-control" required>

       </div>
       <div class="form-group">  
          <label for="nome">Email</label>
          <input type="email" name="email" id="email" placeholder="nome@email.com"class="form-control" required>

       </div>  
       <div class="form-group">  
          <label for="telefone">Telefone</label>
          <input type="tel" name="telefone" id="telefone" placeholder="telefone residencial" class="form-control" >

       </div>
       <div class="form-group">  
          <label for="telefone">Celular</label>
          <input  type="tel" pattern="^\d{2}-\d{5}-\d{4}$" name="celular" id="telefone" placeholder="telefone celular xx-xxxxx-xxxx" class="form-control" required>

       </div>      
       <div class="form-group">
          <label for="endereco">Endereço</label>
          <textarea name="endereco" rows="5" class="form-control"></textarea> 

       </div>

       <div class="form-group">
          <label for="assunto">Assunto</label>
          <input type="text" name="assunto" id="assunto" placeholder="assunto"class="form-control" required>

       </div>
       <div class="form-group">
          <label for="mensagem">Mensagem</label>
          <textarea name="mensagem" rows="5" class="form-control"></textarea> 
       </div>
       <button type="submit" class="btn btn-primary">Enviar</button>   

      </div>
      </form>
    </section>
    <footer>
    <footer>

这部分我展示了我与当地银行的联系:conexao.php

    <?php

      $servidor = "localhost";
      $usuario  = "root";
      $senha    = "";
      $dbname   = "contato";

      //criando a conexao com o banco
      $conn = mysqli_connect($servidor, $usuario, $senha, $dbname);
    ?>

我创建了以下面的方式保存表单数据的页面:

    <?php

      include_once('conexao.php');
      $nome     = $_POST['nome'];
      $email    =$_POST['email'];
      $telefone = $_POST['telefone'];
      $celular  = $_POST['celular'];
      $endereco = $_POST['endereco'];
      $assunto  = $_POST['assunto'];
      $mensagem = $_POST['mensagem'];

      $result_msg_contato = "INSERT INTO tbl_contato(nome, email, telefone, celular, endereco, assunto, mensagem, criada) VALUES ('$nome', '$email', '$telefone', '$celular', '$endereco', '$assunto', '$mensagem', NOW()) "; 
      $resultado_msg_contato = mysqli_query($conn,$result_msg_contato);  
   ?>

从表单输入数据并单击发送后,显示的屏幕全为白色:

[enter image image with the address after you click send here]

1 个答案:

答案 0 :(得分:2)

该主题的标题具有误导性,因为这与PHPMyAdmin没有任何关系。 PHPMyAdmin只是一个用于MYSQL的工具GUI。

最有可能的问题是INSERT查询,但由于您没有使用错误报告,因此无法判断。

尝试以下方法:

<?php

      $link = mysqli_connect('localhost', 'root', '', 'contato');

    /* check connection */
    if (!$link) {
            printf("Connect failed: %s\n", mysqli_connect_error());
            exit();
    }

      $nome     = $_POST['nome'];
      $email    = $_POST['email'];
      $telefone = $_POST['telefone'];
      $celular  = $_POST['celular'];
      $endereco = $_POST['endereco'];
      $assunto  = $_POST['assunto'];
      $mensagem = $_POST['mensagem'];

    $stmt = mysqli_prepare($link, "INSERT INTO tbl_contato (`nome`, `email`, `telefone`, `celular`, `endereco`, `assunto`, `mensagem`, `criada`) VALUES (?, ?, ?, ?, ?, ?, ?, NOW())");
    mysqli_stmt_bind_param($stmt, 'sssssssd', $nome, $email, $telefone, $celular, $endereco, $assunto, $mensagem);

    /* execute prepared statement */
    mysqli_stmt_execute($stmt);

    printf("%d Row inserted.\n", mysqli_stmt_affected_rows($stmt));

    /* close statement and connection */
    mysqli_stmt_close($stmt);