0

I have a page that I wrote to upload a text file to a mysql database. The text file has thousands of lines and each line is a separate database row. An identifier at the beginning of each line tells me which table to insert the line into in the database, so I have it set up to loop through the file. I had it working perfectly, but had to update the code because of a slightly different text file format. Now I am getting the error "Column count doesn't match value count at row 1" after 4,933 lines entered. I explicitly state the column names in the sql statement, and I've double checked that I have the same number of columns and values. I find it odd that it works for so many entries, then gives this error. My code is long, but here it is:

        //$chunk consists of a single line from the text file
        $airportInfo[].=substr($chunk,3,11);
        $airportInfo[].=substr($chunk,14,13);
        $airportInfo[].=substr($chunk,27,4);
        $airportInfo[].=substr($chunk,31,10);
        $airportInfo[].=substr($chunk,41,3);
        $airportInfo[].=substr($chunk,44,4);
        $airportInfo[].=substr($chunk,48,2);
        $airportInfo[].=substr($chunk,50,20);
        $airportInfo[].=substr($chunk,70,21);
        $airportInfo[].=substr($chunk,91,2);
        $airportInfo[].=substr($chunk,93,40);
        $airportInfo[].=substr($chunk,133,50);
        $airportInfo[].=substr($chunk,183,2);
        $airportInfo[].=substr($chunk,185,2);
        $airportInfo[].=substr($chunk,187,35);
        $airportInfo[].=substr($chunk,222,72);
        $airportInfo[].=substr($chunk,294,45);
        $airportInfo[].=substr($chunk,339,16);
        $airportInfo[].=substr($chunk,355,35);
        $airportInfo[].=substr($chunk,390,72);
        $airportInfo[].=substr($chunk,462,45);
        $airportInfo[].=substr($chunk,507,16);
        $airportInfo[].=substr($chunk,523,15);
        $airportInfo[].=substr($chunk,538,12);
        $airportInfo[].=substr($chunk,550,15);
        $airportInfo[].=substr($chunk,565,12);
        $airportInfo[].=substr($chunk,577,1);
        $airportInfo[].=substr($chunk,578,7);
        $airportInfo[].=substr($chunk,585,1);
        $airportInfo[].=substr($chunk,586,3);
        $airportInfo[].=substr($chunk,589,4);
        $airportInfo[].=substr($chunk,593,4);
        $airportInfo[].=substr($chunk,597,30);
        $airportInfo[].=substr($chunk,627,2);
        $airportInfo[].=substr($chunk,629,3);
        $airportInfo[].=substr($chunk,632,5);
        $airportInfo[].=substr($chunk,637,4);
        $airportInfo[].=substr($chunk,641,3);
        $airportInfo[].=substr($chunk,644,30);
        $airportInfo[].=substr($chunk,674,4);
        $airportInfo[].=substr($chunk,678,3);
        $airportInfo[].=substr($chunk,681,30);
        $airportInfo[].=substr($chunk,711,1);
        $airportInfo[].=substr($chunk,712,4);
        $airportInfo[].=substr($chunk,716,30);
        $airportInfo[].=substr($chunk,746,16);
        $airportInfo[].=substr($chunk,762,16);
        $airportInfo[].=substr($chunk,778,4);
        $airportInfo[].=substr($chunk,782,30);
        $airportInfo[].=substr($chunk,812,16);
        $airportInfo[].=substr($chunk,828,4);
        $airportInfo[].=substr($chunk,832,1);
        $airportInfo[].=substr($chunk,833,7);
        $airportInfo[].=substr($chunk,840,2);
        $airportInfo[].=substr($chunk,842,15);
        $airportInfo[].=substr($chunk,857,7);
        $airportInfo[].=substr($chunk,864,13);
        $airportInfo[].=substr($chunk,877,1);
        $airportInfo[].=substr($chunk,878,1);
        $airportInfo[].=substr($chunk,879,1);
        $airportInfo[].=substr($chunk,880,1);
        $airportInfo[].=substr($chunk,881,2);
        $airportInfo[].=substr($chunk,883,1);
        $airportInfo[].=substr($chunk,884,8);
        $airportInfo[].=substr($chunk,892,8);
        $airportInfo[].=substr($chunk,900,40);
        $airportInfo[].=substr($chunk,940,5);
        $airportInfo[].=substr($chunk,945,5);
        $airportInfo[].=substr($chunk,950,8);
        $airportInfo[].=substr($chunk,958,8);
        $airportInfo[].=substr($chunk,966,7);
        $airportInfo[].=substr($chunk,973,7);
        $airportInfo[].=substr($chunk,980,1);
        $airportInfo[].=substr($chunk,981,7);
        $airportInfo[].=substr($chunk,988,7);
        $airportInfo[].=substr($chunk,995,4);
        $airportInfo[].=substr($chunk,999,3);
        $airportInfo[].=substr($chunk,1002,1);
        $airportInfo[].=substr($chunk,1003,1);
        $airportInfo[].=substr($chunk,1004,3);
        $airportInfo[].=substr($chunk,1007,3);
        $airportInfo[].=substr($chunk,1010,3);
        $airportInfo[].=substr($chunk,1013,3);
        $airportInfo[].=substr($chunk,1016,3);
        $airportInfo[].=substr($chunk,1019,3);
        $airportInfo[].=substr($chunk,1022,3);
        $airportInfo[].=substr($chunk,1025,6);
        $airportInfo[].=substr($chunk,1031,6);
        $airportInfo[].=substr($chunk,1037,6);
        $airportInfo[].=substr($chunk,1043,6);
        $airportInfo[].=substr($chunk,1049,6);
        $airportInfo[].=substr($chunk,1055,6);
        $airportInfo[].=substr($chunk,1061,10);
        $airportInfo[].=substr($chunk,1071,16);
        $airportInfo[].=substr($chunk,1087,10);
        $airportInfo[].=substr($chunk,1097,16);
        $airportInfo[].=substr($chunk,1113,10);
        $airportInfo[].=substr($chunk,1123,1);
        $airportInfo[].=substr($chunk,1124,12);
        $airportInfo[].=substr($chunk,1136,71);
        $airportInfo[].=substr($chunk,1207,3);
        $airportInfo[].=substr($chunk,1210,7);
        $sql = "INSERT INTO APT (Landing_Facility_Site_Number, Landing_Facility_Type, Location_Identifier, Information_Effective_Date, FAA_Region_Code, FAA_District_Or_Field_Office_Code, Associated_State_Post_Office_Code, Associated_State_Name, Associated_County_Name, Associated_County_State, Associated_City_Name, Official_Facility_Name, Airport_Ownership_Type, Facility_Use, Facility_Owner_Name, Owner_Address, Owner_City_State_Zip, Owner_Phone, Facility_Manager_Name, Manager_Address, Manager_City_State_Zip, Manager_Phone, Apt_Ref_Point_Lat_Form, Apt_Ref_Point_Lat_Sec, Apt_Ref_Point_Long_Form, Apt_Ref_Point_Long_Sec, Apr_Ref_Point_Det_Meth, Apt_Elev, Apt_Elev_Det_Meth, Mag_Var_Dir, Mag_Var_Epoch, TPA, Sectional, Dist_Biz_Dist, Dir_From_Biz_Dist, Land_Area, Boundary_ARTCC_Ident, Boundary_ARTCC_Comp, Boundary_ARTCC_Name, Responsible_ARTCC_Ident, Responsible_ARTCC_Comp, Responsible_ARTCC_Name, Tie_in_FSS_Physical, Tie_in_FSS_Ident, Tie_in_FSS_Name, Local_FSS_Phone, Toll_Free_FSS_Phone, Alternate_FSS_Ident, Alternate_FSS_Name, Alternate_FSS_TF_Phone, Facility_Resp_Notams, Notam_D_Avail, Apt_Act_Date, Apt_Status, Apt_ARFF_Cert_Date, NPIAS_Fed_Agree_Codes, Apt_Airsp_Analysis_Det, Customs_Entry_Apt, Customs_Landing_Rights_Apt, MC_Joint_Use, Mil_Landing_Rights, Apt_Insp_Meth, Agency_Group_Perform_Phys_Insp, Last_Phys_Insp, Last_Date_Inf_Req_Completed, Fuel_Types_Avail, Airframe_Repair_Service_Avail, Powerplant_Repair_Avail, Type_Bottle_O2, Type_Bulk_O2, APT_Light_Sched, Beacon_Light_Sched, Control_Tower, Unicom, CTAF, Segmented_Circle, Beacon_Lens_Color, Landing_Fee_Charged, Used_For_Med_Purp, SE_GA, ME_GA, Jet_GA, Helicopter_GA, Operational_Gliders, Operational_Military, Ultralight, Commercial_Services, Commuter_Services, Air_Taxi, GA_Local_Ops, GA_Transient_Ops, Military_Ops, Ops_Valid_Date, Apt_Pos_Src, Apt_Pos_Src_Date, Apt_Elev_Src, Apt_Elev_Src_Date, Contract_Fuel_Avail, Transient_Storage, Other_Services, Wind_Indicator, ICAO_Ident)
        VALUES
        ('$airportInfo[0]','$airportInfo[1]','$airportInfo[2]','$airportInfo[3]','$airportInfo[4]','$airportInfo[5]','$airportInfo[6]','$airportInfo[7]','$airportInfo[8]','$airportInfo[9]','$airportInfo[10]','$airportInfo[11]','$airportInfo[12]','airportInfo[13]','$airportInfo[14]','$airportInfo[15]','$airportInfo[16]','$airportInfo[17]','$airportInfo[18]','$airportInfo[19]','$airportInfo[20]','$airportInfo[21]','$airportInfo[22]','$airportInfo[23]','$airportInfo[24]','$airportInfo[25]','$airportInfo[26]','$airportInfo[27]','$airportInfo[28]','$airportInfo[29]','$airportInfo[30]','$airportInfo[31]','$airportInfo[32]','$airportInfo[33]','$airportInfo[34]','$airportInfo[35]','$airportInfo[36]','$airportInfo[37]','$airportInfo[38]','$airportInfo[39]','$airportInfo[40]','$airportInfo[41]','$airportInfo[42]','$airportInfo[43]','$airportInfo[44]','$airportInfo[45]','$airportInfo[46]','$airportInfo[47]','$airportInfo[48]','$airportInfo[49]','$airportInfo[50]','$airportInfo[51]','$airportInfo[52]','$airportInfo[53]','$airportInfo[54]','$airportInfo[55]','$airportInfo[56]','$airportInfo[57]','$airportInfo[58]','$airportInfo[59]','$airportInfo[60]','$airportInfo[61]','$airportInfo[62]','$airportInfo[63]','$airportInfo[64]','$airportInfo[65]','$airportInfo[66]','$airportInfo[67]','$airportInfo[68]','$airportInfo[69]','$airportInfo[70]','$airportInfo[71]','$airportInfo[72]','$airportInfo[73]','$airportInfo[74]','$airportInfo[75]','$airportInfo[76]','$airportInfo[77]','$airportInfo[78]','$airportInfo[79]','$airportInfo[80]','$airportInfo[81]','$airportInfo[82]','$airportInfo[83]','$airportInfo[84]','$airportInfo[85]','$airportInfo[86]','$airportInfo[87]','$airportInfo[88]','$airportInfo[89]','$airportInfo[90]','$airportInfo[91]','$airportInfo[92]','$airportInfo[93]','$airportInfo[94]','$airportInfo[95]','$airportInfo[96]','$airportInfo[97]','$airportInfo[98]','$airportInfo[99]','$airportInfo[100]','$airportInfo[101]')";
        if(!mysql_query($sql,$con))
            {
            die('Error: '.mysql_error());
        }
        else {echo "Airport Info Added!<br/>";}

Any ideas of something I may have overlooked?

2
Contributors
4
Replies
6
Views
5 Years
Discussion Span
Last Post by grant.baker
0

Well, I already us mysql_real_escape_string($chunk) just prior to the code I posted earlier. That should solve any quotation problems. Any other ideas?

1

That's dangerous. If there are quotes somewhere and you use that function, then $chunk will change, causing your substr's to return the wrong values.

Edited by pritaeas: edit

0

Ah, because it adds characters to escape quotes. I hadn't thought of that. Ok, so I changed it to $airportInfo[].=mysql_real_escape_string(substr($chunk,xx,xx));, and that fixed the problem. But I don't understand why it made a difference. Can you explain a bit what causes that error and how that change corrected it?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.