I have a PHP form in which the user enters their data. On submit, it should open an existing CSV file and append some of the data. I have tried a number of things, but here is the most recent code I am currently working with:
HTML:
<html>
<head><title>Design Request</title></head>
<title>Design Request</title>
<form action="test2.php" method="POST">
<fieldset align="left">
<legend>Executive Sponsor Form</legend>
<p><i>To be completed by the executive sponsor</i></p>
<table>
<tr>
<td>Name:</td><td><input type="text" name="SPONSOR_NAME" size="40" /></td>
</tr>
<tr>
<td>Position:</td><td><input type="text" name="SPONSOR_POSITION" size="40" /></td>
</tr>
<tr>
<td>Telephone Number:</td><td><input type="text" name="SPONSOR_TELEPHONE_NUMBER" size="40" maxlength="11" /></td>
</tr>
<tr>
<td>Email Address:</td><td><input type="email" name="SPONSOR_EMAIL" size="40" /></td>
</tr>
<tr>
<td>Budget :</td><td><input type="checkbox" /><input type="text" name="BUDGET" size="37" maxlength="6" placeholder="budget code" /></td>
</tr>
<tr>
<td>Aligned to which<br> priority:</td><td><input type="text" name="PRIORITIES" size="40" /></td>
</tr>
<tr>
<td> Benefit to Business:</td><td><textarea cols="42" rows="10" name="BENEFIT"></textarea></td>
</tr>
</form>
<input type="submit" value="Submit">
PHP:
<html>
<head>
<title>Your (Ref No: ["SPONSOR_NAME"]) has been submitted.</title>
</head>
<?php
$data = array("" . ',' . "SPONSOR_NAME" . ',' . "" . ',' . "" . ',' . "SPONSOR_EMAIL" . ',' . "PRIORITIES" . );
$cr;
$fp = fopen("/var/www/testdb.csv","w");
foreach ($data as $fields){
fputcsv($fp, $fields);
}
fclose($fp);
?>
</html>
Some of the fields are entered on one worksheet where as some are entered on another one thats why I have the array with some empty fields (I want data in column B E and F) the other columns will contain data from another form.