473,320 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

fgetcsv() doesn't get last row in file

2
I have a form set up to allow someone to upload a .csv and populate its data into a database using the fgetcsv() function. All of the code works fine because everything in the .csv file is populated into the database just fine, except for the very last row of data. I have tried several different ways of using the fgetcsv(), including:
[php]
while ($result = fgetcsv($handle)) {

while (($result = fgetcsv($handle)) != false) {

while (($result = fgetcsv($handle)) !== false) {
[/php]
I have tried each one of these also using the optional $length, $delimiter, and $enclosure parameters, but to no avail.

I am using the function exactly (as far as I can tell) as it is shown on php.net, but cannot figure out why the last row of my file would not be included in the database... any suggestions? Server is running PHP 5.2.5
Mar 19 '08 #1
3 3504
ronverdonk
4,258 Expert 4TB
A known error is that "If the last char of the CSV file isn't a carriage return, the function can't take the last field of the last line in the CSV.".

Is this what happened? If not, show some more code of your script. Maybe it is somwhere else. (and show any code within appropriate code tags).

Ronald
Mar 19 '08 #2
jrrdnx
2
Thanks for the tip... that got me into looking at the code that inserted the data in the database. It turns out I hadn't accounted for single quotes in some of the fields that was breaking up my arguments. I actually had about 10 rows not being entered into the database.
Mar 19 '08 #3
ronverdonk
4,258 Expert 4TB
Does that mean that your original problem, why you started the thread, is now solved?

Ronald
Mar 19 '08 #4

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

Similar topics

2
by: Joe Randstein | last post by:
Hi! I get CSV-data from a post-request. How can I work on that? Currently I save the data to a temp-file, then read it back with fgetcsv and then delete the temp-file. That works, but I don't...
2
by: Bengt Richter | last post by:
Is this a well known bug that's been fixed? I couldn't find any discussion of it, but maybe my googling's off today ;-/ >>> def foo(): ... it = iter(range(10)) ... while True: ... ...
2
by: Stephen Preston | last post by:
I have an xls worksheet I wish to export as a text or csv file to import with fgetcsv() The 'save as' function on excell lets me save as a comma separated value or tab delimited text files....
1
by: Jonaed | last post by:
This is my code: $handle = fopen ($file, "r"); $c = 1; while (($values_list = fgetcsv ($handle, 1000, ',', '"')) !== FALSE) { echo $c . "<br>\n"; $c = $c +...
0
by: tjonsek | last post by:
I am working with directories in PHP for the first time. I have code that I've changed multiple times to try different things. I would think this is pretty standard fare so I'm not sure why I can't...
0
by: et | last post by:
fgetcsv() do unwanted "left trim" on fields started with locale characters (code page win-1250). Problem persist only if local character is first character in field for example, let say that C...
5
by: mantrid | last post by:
I am using fopen() and fgetcsv() to open an excel file and extract data for upload to mysql database. The doesnt seem to be a parameter in either of these functions for ommitting the first row of...
2
code green
by: code green | last post by:
I am trying to skip empty rows in a csv file The manual states But none of these tests seem to work. Anybody know why while(($data = fgetcsv($this->handle)) !== false) { ...
14
by: Rafe | last post by:
Hi, I've encountered a problem which is making debugging less obvious than it should be. The @property decorator doesn't always raise exceptions. It seems like it is bound to the class but...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.