添加时间戳并将不成功的数据库条目添加到pdf

I've just started out programming in PHP & MYSQL. I'm wanting to create a CSV file importer that then writes entries to a database, but with various validations. I wanted to add a current time and date to the datetime column in which any products that are discontinued when the database says "Yes" will issue a date and time of the product being discontinued. I also want to add entries to a PDF file/ report format of various error conditions. The errors would include any entries that did not pass the if conditions such as regular expressions and were not added to the database.

<?php
    include_once('connection.php');
    date_default_timezone_set('Europe/London');
    $date = date('d/m/y h:i:s a', time());
    $filetxt = "./errors.txt";
    $var1 = 5;
    $var2 = 1000;
    $var3 = 10;
    if(isset($_POST["Import"]))
    {
        echo $filename=$_FILES["file"]["tmp_name"]; 
        if($_FILES["file"]["size"] > 0)
        {
            $file = fopen($filename, "r");
            while(($emapData = fgetcsv($file, 10000, ",")) !==FALSE)
            {
                // adds data to the sql database
                if($var1 <= $emapData[3] && $var3 <= $emapData[4] && $var2 >= $emapData[4] && preg_match("/^[a-zA-Z0-9]+$/", $value) == $emapData[1] && preg_match("[a-zA-Z]", $value) == $emapData[2] && preg_match("[a-zA-Z]", $value) == $emapData[6]){
                $sql = "INSERT INTO tblproductdata(strProductCode, strProductName, strProductDesc, intStock, intPrice, dtmAdded, dtmDiscontinued) VALUES('$emapData[0]','$emapData[1]','$emapData[2]','$emapData[3]','$emapData[4]','$date','$date')";
                echo "test 1";
                }
                else if($var1 <= $emapData[3] && $var3 <= $emapData[4] && $var2 >= $emapData[4] && preg_match("/^[a-zA-Z0-9]+$/", $value) == $emapData[1] && preg_match("[a-zA-Z]", $value) == $emapData[2] && preg_match("[\s]", $value) == $emapData[6]){
                    $sql = "INSERT INTO tblproductdata(strProductCode, strProductName, strProductDesc, intStock, intPrice, dtmAdded, dtmDiscontinued) VALUES('$emapData[0]','$emapData[1]','$emapData[2]','$emapData[3]','$emapData[4]','null','null')";
                    echo "test 2";
                    }
                else{   
                $write = "$emapData[0], $emapData[1], $emapData[2], $emapData[3], $emapData[4], $emapData[5], $emapData[6], $emapData[7]

";   
                 file_put_contents($filetxt , $write , FILE_APPEND);
                }
                $res=$conn->query($sql);
            }
            echo "$sql";
            fclose($file);
            echo "CSV File has successfully been Imported";
        }
        else
        {
            echo "Invalid File: Please Upload a Valid CSV File";
        }
    }
header("Location: index.php");
?>

I especially need help with adding the unsuccessful database entries to a PDF.

Storing current date and time

MySQL supports two different formats for storing dates with times, datetime and timestamp. I will show examples with timestamp here.

You can also tell MySQL to fill your field with the current date and time whenever a row is inserted (read more here). The SQL for creating the table then looks somewhat like this:

CREATE TABLE test (
  name CHAR(30),
  time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)

If you insert into the table without setting a value for time, it will set the current time:

INSERT INTO(name) VALUES("some text")

You can also set the value manually:

INSERT INTO(name, time) VALUES("some text", CURRENT_TIMESTAMP)

Writing to a PDF

Have a look at FPDF. However, for just writing an error log a normal text file would be much simpler and perhaps more suitable.