Comment doesn't save to File

when I to fill in my Webform Name, Email and Message , it not display on my Website , too it not to save to my file test.txt … , the test.txt File is on my Home Directory .With this Code I can to do this in my computer . I receive this warning :

Notice: Undefined index: Name in /storage/ssd2/418/6831418/public_html/classprove.php on line 93

Notice: Undefined index: Email in /storage/ssd2/418/6831418/public_html/classprove.php on line 94

Notice: Undefined index: Message in /storage/ssd2/418/6831418/public_html/classprove.php on line 95

On Line 93, 94 and 95 i have this:

        $this->Name = trim($_POST['Name']);
        $this->Email = trim($_POST['Email']);
        $this->Message = trim($_POST['Message']); 

My Code from classprove.php

<?php

header('Content-Type: text/html; Charset=utf-8');
mb_internal_encoding('UTF-8');
date_default_timezone_set('Europe/Berlin');


class classprove {

  private $Name;
  private $Email;
  private $Message;


function __construct() {



    $this->Name="";

    $this->Email="";

    $this->Message="";


}





 
 
 function Form() {

 


    echo('<table>');


                echo('<label for="name">Name </label>');



                echo('<input type="text" name="Name" value="'.$this->Name.'">');



                echo('<label for="email"> E-mail </label>');



                echo('<input type="email" value="'.$this->Email.'" name="Email" ');





          echo('<tr>');



             echo('<td>');

                 echo('<br>');

                 echo('<label> Message: <br><textarea cols="45" rows="6" name="Message">'.$this->Message.'</textarea></label>');

                 echo('<br><br>');

                 echo('<input  type="submit" name="post" value="POST COMMENT" id="comment">');



             echo('</td>');



          echo('</tr>');



     echo('</table>');


  }

  function GetPostData() {
  
       if (isset($_POST["Name"]) || empty($_POST["Email"]) || empty($_POST["Message"]))
       {
        $this->Name = trim($_POST["Name"]);
        $this->Email = trim($_POST["Email"]);
        $this->Message = trim($_POST["Message"]); 
       }    
            
   
 } 

   
   
 function PostOk()

 {
          
    


           if (!isset($_POST['post'])) {
          
              return;
           } 
               if (empty($this->Name) ||  empty($this->Email) || empty($this->Message))
               {
               
                   echo "<br>" . "<b>" . "<h3>*** Please enter all required fields ***</h3>" . "</b>";  
           
               }
        

      
               else  
               {
                  
                   
                   $file = "test.txt"; 
                   $file = FILE_USE_INCLUDE_PAT($file);
                   
                   $name = filter_input( INPUT_POST, 'Name', FILTER_SANITIZE_STRING);
                   $email = filter_input(INPUT_POST, 'Email', FILTER_SANITIZE_STRING);
                   $message = filter_input(INPUT_POST, 'Message', FILTER_SANITIZE_STRING);
                   $datetime = date('m/d/Y h:i:s a', time());
                   
                   $data = array("name" => $name, "email" => $email, "message" => $message, "datetime" => $datetime);
	   
			           $data = serialize($data);
		              file_put_contents($file, $data . "\n", FILE_APPEND|LOCK_EX);
                   
                   
                   $messages = file($file);
 
			           foreach ($messages as $value) {
		                $data = unserialize($value);
				                  
    

                              echo "<br>"

                                  . "<b>From: </b>" . htmlspecialchars( $data["name"])
                                  . "<b> at: </b>" . htmlspecialchars( $data["datetime"])
                                  . "<br><br>" . htmlspecialchars( $data["email"])                                     
                                  . "<br><br>" . htmlspecialchars( $data["message"])
                                  . "<br><hr>";
    
                   }
           
                }  
        
       
      }


 } 


?>

screenshot from my directory

This clearly says that the $_POST parameters are not set

thanks for your answer ! i am vey new mit html/css and php…

how a understand with ;

     $this->Name = trim($_POST['Name']);
     $this->Email = trim($_POST['Email']);
     $this->Message = trim($_POST['Message']);  

this are the on Line 94, 95, 96 , have back the Variable from Post …

Please post your form’s HTML here :slight_smile:

My HTML form ;

<form action="classprove.php" method="POST" id="form">

                
               <?php

                    $ProveContackt->GetPostData(); 
 
                    $ProveContackt->form();

                    $ProveContackt->PostOk();

           ?>    
	


</form>

The final HTML one :slight_smile:

Thanks , sorry because not answer your before what i should to sleeping , i muss going to work…

Now i have not this problem , but when fill in form Name, Email and Message them not display…

1 Like

I found the solution ! :grinning:

my problem was from mine form from Index File . On the form I has

<form action="classprove.php"

so , where i have my Code for form , the correct it is

<form action="index.php"