php - Adding time stamp and adding unsuccessful database entries to a pdf -
i've started out programming in php & mysql. i'm wanting create csv file importer writes entries database, various validations. wanted add current time , date datetime column in products discontinued when database says "yes" issue date , time of product being discontinued. want add entries pdf file/ report format of various error conditions. errors include entries did not pass if conditions such regular expressions , not added 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 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 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 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]\n\n";                     file_put_contents($filetxt , $write , file_append);                 }                 $res=$conn->query($sql);             }             echo "$sql";             fclose($file);             echo "csv file has been imported";         }         else         {             echo "invalid file: please upload valid csv file";         }     } header("location: index.php"); ?> i need adding unsuccessful database entries pdf.
storing current date , time
mysql supports two different formats storing dates times, datetime , timestamp. show examples timestamp here.
you can tell mysql fill field current date , time whenever row inserted (read more here). sql creating table looks this:
create table test (   name char(30),   time timestamp default current_timestamp ) if insert table without setting value time, set current time:
insert into(name) values("some text") you can set value manually:
insert into(name, time) values("some text", current_timestamp) writing pdf
have @ fpdf. however, writing error log normal text file simpler , perhaps more suitable.
Comments
Post a Comment