With the help of this post and another friend explaining me in detail, we all managed to get it working , as a reference I will post the final code and is available for those that need it, passing on the knowledge as well . I thank you Ch0cu3r and Hansford, you guys have been great help.
<?php
if(isset($_POST['submit'])){
//collect form data
$location = $_POST['location'];
$ID = $_POST['ID'];
$section = $_POST['section'];
//check name is set
if($location ==''){
$error[] = 'Name is required';
}
//if no errors carry on
if(!isset($error)){
$list = array(
'location','ID','section',
$location, $ID, $section,
);
# set the file name and create CSV file
$my_file_name = ("$location$ID$section.cvs");
$file = fopen("$my_file_name", "w");
foreach($list as $line){
fputcsv($file,explode(',',$line),',');
}
fclose($file);
}
}
//if their are errors display them
if(isset($error)){
foreach($error as $error){
echo "<p style='color:#ff0000'>$error</p>";
}
}
?>
<form action='' method='post'>
<p><label>Location:</label><br><input type='text' name='location' value=''></p>
<p><label>ID:</label><br><input type='text' name='ID' value=''></p>
<p><label>Section:</label><br><input type='text' name='section' value=''></p>
<p><input type='submit' name='submit' value='Submit'></p>
</form>