storing php fom data values into csv file dirctly

this is my code:-
sample1.php

name

Address

Town

Phone

email

sample2.php

<?php $n=$_POST['name']; $a=$_POST['address']; $t=$_POST['town']; $p=$_POST['phone']; $e=$_POST['email']; $string = "$n,$a,$t,$p,$e"; $newline="\r\n"; $filename = "details.csv"; if (file_exists($filename)) { $file = fopen($filename, "a"); fwrite($file, $newline); fwrite($file, $string); } else { $file = fopen($filename, "a"); fwrite($file, '"Name","Address","Town","Phone","Email"'); fwrite($file, $newline); fwrite($file, $string); } fclose($file); ?>

This code works fine if there is only one line in the text area. If we enter more than one line by pressing the enter key the code doesnot work.The data is inserted into the file,but not under corresponding column.

For everyone this may seem stupid question.But am a beginner in PHP.Please anyone help.

Hi there,

The newline character can be different depending on the machine/browser etc. Try the following:

[php]$a = str_replace(array("\r\n","\r","\n")," ",$_POST[‘address’]);[/php]

Thanks a lot …It worked.

Sponsor our Newsletter | Privacy Policy | Terms of Service