kenwvs Posted July 11, 2006 Share Posted July 11, 2006 I have an html form that once it has been completed, a php script takes over and saves it to a csv file and lets you save it as well as send it back to you by email. In one of the fields you fill in, it would be very common to use a comma (,) which causes an additional field to be created. Normally, if you use quotation marks (") at the start and end of this field, it will ignore the comma and keep all the text as one field. I am not able to figure out how to get it to do this in either to form or the script.The field that causes the grief is item_description. In my novice mind, I thought adding the quotation marks in the script on the outside of the ' might work, but it didn't and then tried it on the inside of the ' and that didn't work either. Just had a thought and am wondering if you can put them inside the input field of the form and have them hidden, so the users can't take them out. Not sure, but here is the script and partial form.The php script being used is:[code]<?php$flds = array('item_title','item_category','item_type','quantity_available','starting_bid/price','bid_increment','reserve_price','duration','auto_relist','city','state','country',"'item_description'",'paypal_id','hit_counter','end_hour');$write_to_csv = 'UploadForm/' . $_POST['id'] . '.csv';if (!file_exists($write_to_csv)) { // only write the header if the file doesn't already exist $fp = fopen($write_to_csv,'a'); fwrite($fp,implode(',',$flds)."\n"); // write the field names separated by commas fclose($fp); }$fp = fopen($write_to_csv,'a');$tmp = array();foreach($flds as $fld) $tmp[] = $_POST[$fld]; // put the values in the temp array in the correct order.fwrite($fp,implode(',',$tmp)."\n"); // write to the filefclose($fp);header("Location: http://www.forsale4u.ca/uploadformconfirmation.html");?>[/code]As the html form is quite long, I am including only the portion around the field in question. [quote]<p><font face="Arial"><font size="2">Item Description </font> <font size="3"> <textarea rows="4" name="item_description" cols="108"></textarea></font></font></p> [/quote] Quote Link to comment https://forums.phpfreaks.com/topic/14320-resolved-form-php-script-and-csv-file-and-a-darn-comma-is-causing-a-problem/ Share on other sites More sharing options...
Barand Posted July 11, 2006 Share Posted July 11, 2006 [code]<?phpwhile ($flds = mysql_fetch_row($result)) { fwrite($fp, '"'. implode('","',$flds)."\"\n"); // write to the file}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/14320-resolved-form-php-script-and-csv-file-and-a-darn-comma-is-causing-a-problem/#findComment-56415 Share on other sites More sharing options...
kenwvs Posted July 11, 2006 Author Share Posted July 11, 2006 by doing it this way, would it still sort the file into the order that I need it in. Is the line you added going right after the line with the first $tmp[]. I am not sure I am understanding what is going to happen here.Ken Quote Link to comment https://forums.phpfreaks.com/topic/14320-resolved-form-php-script-and-csv-file-and-a-darn-comma-is-causing-a-problem/#findComment-56453 Share on other sites More sharing options...
Barand Posted July 11, 2006 Share Posted July 11, 2006 if $flds is the array of values you want to write to the file, then this will put ".." round each value in the csvfwrite($fp, '"'. implode('","',$flds)."\"\n"); // write to the file Quote Link to comment https://forums.phpfreaks.com/topic/14320-resolved-form-php-script-and-csv-file-and-a-darn-comma-is-causing-a-problem/#findComment-56454 Share on other sites More sharing options...
kenwvs Posted July 11, 2006 Author Share Posted July 11, 2006 That solved my Problem. Thank You very much Quote Link to comment https://forums.phpfreaks.com/topic/14320-resolved-form-php-script-and-csv-file-and-a-darn-comma-is-causing-a-problem/#findComment-56466 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.