I have created a web based print log that sends the form data to a .CSV file using PHP. Everything seems to be working correctly. Although, I have found one small bug that I cannot seem to resolve (yet).
There are seven entries on the print log that submit to the .CSV file. Two of those entries are drop down lists that are being populated from two different .DAT files which are updated on a daily basis.
The issue:
After successfully submitting the form data and opening the .CSV file, I notice that the two entities that use drop down lists are formatted different than the rest of the data.
You can see what I mean by viewing the following screen shot:
http://i49.tinypic.com/2n87eko.jpg
I believe the issue is coming from the following code that pulls the “Project Number” and “Employee Name” drop down box data:
<?php
$file = 'dat_files/Employees.dat';
$handle = @fopen($file, 'r');
if ($handle) {
while (!feof($handle)) {
$line = fgets($handle, 4096);
$item = explode('|', $line);
echo '<option value="' . $item[0] . '">' . $item[0] . '</option>' . "\n";
}
fclose($handle);
}
?>
Any help or ideas would be greatly appreciated. Thank you.
Below is the code that is used to send the form data to the .CSV file.
<?php
if(isset($_POST["submit"]))
{
$type = $_POST["type"];
$date = $_POST["date"];
$job_number = $_POST["job_number"];
$phase = $_POST["phase"];
$task = $_POST["task"];
$number_copies = $_POST["number_copies"];
$name = $_POST["name"];
if(empty($type)||empty($date)||empty($job_number)||empty($phase)||empty($task)||empty($number_copies)||empty($name))
{
header('Location: submit/unsuccessful.htm');
die;
}
$cvsData = "\"$type\",\"$date\",\"$job_number\",\"$phase\",\"$task\",\"$number_copies\",\"$name\"".PHP_EOL;
$fp = fopen("log.csv", "a");
if($fp)
{
fwrite($fp,$cvsData); // Write information to the file
fclose($fp); // Close the file
header('Location: submit/successful.htm');
}
}
?>
I am guessing, but am not really sure that the code you show is the code that echos the data to the screen inside the table shown in the screenshot. if that is true then what are all the option tags about?
if not true, then we probably need to see a bit more source code to help you.