By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,304 Members | 1,242 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,304 IT Pros & Developers. It's quick & easy.

saving to .csv from html form

P: 2
So I have figured out all of the initial setup issues but now I am stumped. Mostly because I don't even know what to search for to answer my question. I have an html form online and when people click submit it send me the information in an email and it saves the data to a .csv file on my server. and now the question.

When people are writing an entry in the message or the name box, if they use a comma, then everything after the comma gets put in the next column over in my .csv file even though it is not the next entry yet.

How to I get all the form data in each box to stay in each column. Is there a comma stripping trick to remove commas from entries or hat can I do??

I read somewhere about putting the info in " " but I don't know what that means orhow to implement it. I have the code available but the actual forms are on a secure intranet for the DoD so I can't just send you a link
Oct 23 '08 #1
Share this Question
Share on Google+
3 Replies

P: 44
There are two ways you can fix this problem. The best way is to enclose the data in quotes as you mentioned, so if you have someone put in a name like John Doe, Jr. you store it as "John Doe, Jr." so the extra comma won't break anything. This should be a simple matter of adding quotes in the string you are writing to the file, just be sure to escape the quotes, maybe something like this:

Expand|Select|Wrap|Line Numbers
  1. $str_to_file = "\"".$_REQUEST['name_from_form']."\",";
Then when you parse it, use the 3 characters "," as the delimiter instead of just ,

If you'd like to just remove the commas altogether, try:

Expand|Select|Wrap|Line Numbers
  1. $name = str_replace(",", "", $name);
Hope that helps.
Oct 23 '08 #2

Expert 5K+
P: 5,058

You could try using the fputcsv function. It should make sure that data that includes commas is properly quoted.

And to make sure the data is properly read in again, you could use the fgetcsv function.
Oct 23 '08 #3

P: 2
Thanks for the help. I will try to get this in tonight. It sounds exactly like what I need.
Oct 23 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.