Forum Moderators: coopster
<?php
$filename = "filename.csv";
$string = '"'.$_POST['id'].'","'.$_POST['email'].'" \n';
if (file_exists($filename)) {
$file = fopen($filename, "a");
fwrite($file, $string);
} else {
$file = fopen($filename, "a");
fwrite($file, '"id","Email" \n');
fwrite($file, $string);
}
fclose($file);
header( "Location: www.my-domain.com/success" );
?>
$string = 'This is what I want inserted into the file \n';
<?php
$id = $_POST['id'];
$email = $_POST['email'];
$fp = fopen("filename.csv", "a");
$savestring = $id . "," . $email . "\n";
fwrite($fp, $savestring);
fclose($fp);
echo "Your data has been saved!";
?>
<?php
$filename = "filename.csv";
$string = $_POST['id'].",".$_POST['email']."\n\r';<--Concatenated your vars properly here
if(file_exists($filename)){
$file = fopen($filename, 'a');
$success = fwrite($file, $string);
//Handle a failed write here
if($success == FALSE){
echo "something went wrong writing to file";
exit;
}
}
else{
//this part means that the file wasnt there so
//you can't write to it?
$file = fopen($filename, "a");
fwrite($file, "id, Email\n\r");<--Syntax error was here
fwrite($file, $string);
}
//close file handle
fclose($file);
header("Location: www.my-domain.com/success");
//kill the script after header, goo practise to do this ;)
exit;
?>