I try to write from html form to csv file using php. I have a problem that nothing is wrote in the file .
I want to be like this:
a,b,c,d
and if I have an empty input, it will be like this
a,,b,c,d
This is the code, what's wrong on it?
$csv=array();
$number=$_POST['txt_number'];
$description=$_POST['txt_description'];
$division=$_POST['txt_division'];
$stage=$_POST['txt_stage'];
$category=$_POST['txt_category'];
$priority=$_POST['txt_priority'];
$frequency=$_POST['txt_frequency'];
$notapprove=$_POST['txt_notapprove'];
$approve=$_POST['txt_approve'];
$notexist=$_POST['txt_notexist'];
$wo=$_POST['txt_wo'];
$duration=$_POST['duration'];
$startdate=$_POST['startdate'];
$enddate=$_POST['enddate'];
$asd=$_POST['txt_asd'];
$add=$_POST['txt_add'];
$aduration=$_POST['txt_aduration'];
$transferredto=$_POST['txt_transferredto'];
$prb=$_POST['txt_percentage'];
$note=$_POST['txt_note'];
$projectname=$_POST['txt_projectname'];
if($exist=="Not Approve"){$a="Not Approve";}
if($exist=="Approve"){$b="Approve";}
if($exist=="Not Exist"){$c="Not Exist";}
$csv[]=$number;
$csv[]=$description;
$csv[]=$division;
$csv[]=$stage;
$csv[]=$category;
$csv[]=$priority;
$csv[]=$frequency;
$csv[]=$notapprove;
$csv[]=$approve;
$csv[]=$notexist;
$csv[]=$wo;
$csv[]=$duration;
$csv[]=$startdate;
$csv[]=$enddate;
$csv[]=$asd;
$csv[]=$add;
$csv[]=$aduration;
$csv[]=$transferredto;
$csv[]=$prb;
$csv[]=$note;
$csv[]=$projectname;
$csv[]=$a;
$csv[]=$b;
$csv[]=$c;
$file = fopen("contacts.csv","w");
foreach ($csv as $line)
{
fputcsv($csv,$line);
}
fclose($file);