I have created an HTML web based print log that sends its form data into a .CSV file using PHP. Everything is set up and working perfectly. Now, I am trying to add a new feature that when the form is submitted it multiplies the “number of copies” by the “type” which is technically the price per copy and sends the result into an additional cell in the .CSV file.
So to recap; the form sends all of the user filled data into the CSV file correctly. I would just like to add another item into the CSV file that is generated by multiplying the number of copies by the type (which is technically the price per copy) when the form is submitted.
I’m not really sure on how to go about doing this. I’m also not sure if PHP is an option. Any ideas would be greatly appreciated. For a better visual, I attached a screen shot below:
http://i47.tinypic.com/2rpz1xh.jpg
Code that is sending the form data to the CSV:
<?php
if(isset($_POST["submit"]))
{
$type = trim($_POST["type"]);
$date = $_POST["date"];
$job_number = trim($_POST["job_number"]);
$phase = $_POST["phase"];
$task = $_POST["task"];
$number_copies = $_POST["number_copies"];
$name = trim($_POST["name"]);
$comment = $_POST["comment"];
if(empty($type)||empty($date)||empty($job_number)||empty($number_copies)||empty($name))
{
header('Location: submit/unsuccessful.htm');
die;
}
$cvsData = "\"$job_number\",\"$phase\",\"$task\",\"$date\",\"$comment\",\"$type\",\"$number_copies\"".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');
}
}
?>
You could do it by simply multiplying your variables: