Jump to content

write form data to .csv file


perfectspa

Recommended Posts

can anyone tell me what is wrong with the following code.  When I run my form i am always just getting the error message  Warning: fopen(youth.csv): failed to open stream: Cannot open file (youth.csv)

 

 

(I am not very clued up and this code has been generated from from PHP Form Wizard ... but doesn't seem to work)

thanks

ali

x

 

 

//saving record in a text file

$pfw_file_name = "youth.csv";

$pfw_first_raw = "name,age,email,myspace,Address,Tel_Number,Mobile_Number,parentguardian_name,favourite_activity,who_runs,where,day_time,favourite_thing,how_long,recommend,travel,links,others,receive_texts,receive_email\r\n";

$pfw_values = "$name,$age,$email,$myspace,".str_replace ("\r\n","<BR>",$Address ).",$Tel_Number,$Mobile_Number,$parentguardian_name,".str_replace ("\r\n","<BR>",$favourite_activity ).",$who_runs,$where,$day_time,$favourite_thing,$how_long,$recommend,$travel,$links,".str_replace ("\r\n","<BR>",$others ).",$receive_texts,$receive_email\r\n";

$pfw_is_first_row = false;

if(!file_exists($pfw_file_name))

{

$pfw_is_first_row = true ;

}

if (!$pfw_handle = fopen($pfw_file_name, 'a+')) {

die("Cannot open file ($pfw_file_name)");

exit;

}

if ($pfw_is_first_row)

{

  if (fwrite($pfw_handle, $pfw_first_raw ) === FALSE) {

  die("Cannot write to file ($pfw_filename)");

  exit;

  }

}

if (fwrite($pfw_handle, $pfw_values) === FALSE) {

  die("Cannot write to file ($pfw_filename)");

  exit;

}

fclose($pfw_handle);

Link to comment
https://forums.phpfreaks.com/topic/40165-write-form-data-to-csv-file/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.