Phpmyadmin collecting data unnecessarily?

Asked

Viewed 35 times

-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 loop in a table, but I was able to insert and place the comment in the table row, but when it updates, the other rows send to the database empty spaces.

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

  • My complicated understand your doubt, but I think this is it: checks if there is a Session, if there is no Insert and creates a Session after the Insert.

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 */

?>
  • Please explain the solution.

  • According to the question: "the other rows send to the empty spaces database." So what I did was validate if the information is not null with the code below the comment: /* Checks if there are values to insert */

Browser other questions tagged

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