I am trying to write to a CSV file using my form from my website, but it's not writing anything to it but instead just making me upload another CSV file.
My code:
The form code:
<form action="" method="post">
<fieldset style="float:left; text-align: left">
<legend>Add Users</legend>
<label for="fn">
First Name: <input type="text" id="fn" name="fn" onkeypress="fill()" required="required" placeholder="First Name" size="20"/>
</label>
<label for="ln" >
Last Name: <input type="text" id="ln" name="ln" onkeyup="fill()" required="required" placeholder="Last Name" size="20"/>
</label>
<br/>
<label for="full">
Full Name: <input type="box" id="full" name="full" required="required" placeholder="Full Name" size="54"/>
</label>
<br/>
<label for="log">
User Logon: <input type="text" id="log" name="log" onkeypress="fill2()" required="required" placeholder="User Logon" size="27"/>
</label>
<select>
<option value="test">
test
</option>
</select>
<br/>
<label for="log2">
User logon name (pre-Windows 2003): <select>
<option value="test\">
test\
</option>
</select><input type="text" id="log2" name="log2" required="required" placeholder="Username" size="20"/>
</label>
<br/>
<label for="pwd">
Password: <input type="password" id="pwd" name="pwd" required="required" placeholder="Password" size="20"/>
</label>
<label for="cpwd">
Confirm Password: <input type="password" id="pwd" name="cpwd" required="required" placeholder="Password" size="20"/>
</label>
<p for="1st" style="font-size: 16px"><input type="checkbox" id="1st" name="1st" value="1st"/>User must change password at next logon</p>
<p for="2nd" style="font-size: 16px"><input type="checkbox" id="2nd" name="2nd" value="2nd"/>User cannot change password</p>
<p for="3rd" style="font-size: 16px"><input type="checkbox" id="3rd" name="3rd" value="3rd"/>Password never expires</p>
<p for="4th" style="font-size: 16px"><input type="checkbox" id="4th" name="4th" value="4th"/>Account is disabled</p>
<input type='submit' name='submit' value='Add User'>
<button type="reset" value="Clear" onclick="" id="auser">Clear</button>
</fieldset>
</form>
The php code:
if(isset($_POST['submit']))
{
//collect form data
$fn = $_POST['fn'];
$ln = $_POST['ln'];
$full = $_POST['full'];
$log = $_POST['log'];
$log2 = $_POST['log2'];
$pwd = $_POST['pwd'];
//if no errors carry on
if(!isset($error))
{
# Title of the CSV
$title = "First Name, Last Name, Full Name, User Logon, User Logon(pre-2003), Password,
";
$space = "
";
//set the data of the CSV
$Content = "$fn, $ln, $full, $log, $log2, $pwd
";
# set the file name and create CSV file
$FileName = ("adduser.csv");
header('Content-Type: application/csv');
header('Content-Disposition: attachment; filename="' . $FileName . '"');
echo $title;
echo $space;
echo $Content;
exit();
}
}
What I need is that, when I press add user on the form, it will add that user to the adduser.csv file, but right now its just, like I said, making me download a CSV file, and not writing to the adduser.csv file.