perfectspa Posted February 26, 2007 Share Posted February 26, 2007 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 More sharing options...
Yesideez Posted February 26, 2007 Share Posted February 26, 2007 Check that you have permission on the server to create the file. Link to comment https://forums.phpfreaks.com/topic/40165-write-form-data-to-csv-file/#findComment-194316 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.