PHPMyAdmin collecting data unnecessarily?

-1

Below the code I have to collect the $_POST

<?php
     $conexao = mysql_connect("localhost:3306",'user1','senhadementirinha');
     $bd = mysql_select_db("recados");
 ?>

    <form name="form" method="post" action="#">
         Nome:
          <input type=text name=nome><br><br>

         E-Mail:
          <input type=text name=email><br><br>

         Mensagem:
           <textarea name=post></textarea><br><br>

         <input type=submit value=Enviar>

         <input type=reset value=Limpar>
    </form>

<?php

    $nome=$_POST['nome'];         
    $post=$_POST['post'];
    $data = date("Y/m/d");

      $insert = mysql_query("INSERT INTO msg(nome,post,data) values ('$nome','$post','$date')");

      $sql = "SELECT * FROM msg ORDER BY id desc";

      $executar = mysql_query($sql);    

   while( $exibir = mysql_fetch_array($executar)){
        echo $exibir['date'];
        echo $exibir['post'];
        echo "</br><hr>";
   }

?>

This code is used in a loop in a table, but I was able to insert and put the comment in the table row, but when it updates it, the other lines send empty spaces to the database.

One way to solve would be to have a checkbox but I do not know if it is possible after it is selected, it will remain even after updating the page.

    
asked by anonymous 22.11.2017 / 14:45

1 answer

0

Try this:

<?php
$nome=$_POST['nome'];         
$post=$_POST['post'];
$data = date("Y/m/d");

/* Verifica se existe valores a inserir */
if($nome != null &&
      $post != null &&
      $data != null){

$insert = mysql_query("INSERT INTO msg(nome,post,data) 
values('$nome','$post','$date')");


$sql = "SELECT * FROM msg ORDER BY id desc";


$executar = mysql_query($sql);

while( $exibir = mysql_fetch_array($executar)){
echo $exibir['date'];

echo $exibir['post'];
echo "</br><hr>";
}

} /* fim do if != null */

?>
    
22.11.2017 / 16:27