![]() |
CSV upload, once uploaded to a temp folder overwrite the existing database - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: CSV upload, once uploaded to a temp folder overwrite the existing database (/showthread.php?tid=57525) |
CSV upload, once uploaded to a temp folder overwrite the existing database - El Forum - 03-22-2013 [eluser]the_unforgiven[/eluser] Following on from what was said, i'm now having trouble saving it to the db. by this line from the code above: Code: $sql = "INSERT INTO wc_program_temp VALUES "; Error is: Error Number: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 INSERT INTO wc_program_temp VALUES ; So what should I do? Code is exactly the same in the 2nd post by davidMC1982 CSV upload, once uploaded to a temp folder overwrite the existing database - El Forum - 03-22-2013 [eluser]TheFuzzy0ne[/eluser] The problem is still exactly the same as what I explained [url="http://ellislab.com/forums/viewthread/234195/#1050153"]here[/url]. Debug, debug, debug! CSV upload, once uploaded to a temp folder overwrite the existing database - El Forum - 03-22-2013 [eluser]the_unforgiven[/eluser] That's just it i have but cant find what it is hence coming back to the forums for help.... ![]() CSV upload, once uploaded to a temp folder overwrite the existing database - El Forum - 03-23-2013 [eluser]the_unforgiven[/eluser] Any1 else willing to offer some advice/help? CSV upload, once uploaded to a temp folder overwrite the existing database - El Forum - 03-23-2013 [eluser]the_unforgiven[/eluser] Ok i figured this out byt going back to basics and debugging using the following code Code: $data = file_get_contents("http://localhost/sussex/assets/uploads/wc_program.csv"); But then i get this error: Code: Error Number: 1064 CSV upload, once uploaded to a temp folder overwrite the existing database - El Forum - 03-24-2013 [eluser]TheFuzzy0ne[/eluser] Just replace a single apostrophe with two apostrophes. Code: // So... CSV upload, once uploaded to a temp folder overwrite the existing database - El Forum - 03-24-2013 [eluser]the_unforgiven[/eluser] That's not going to work with what i have in http://ellislab.com/forums/viewthread/234195/#1050313 will it has I dont have what was originally posted with the $sql var CSV upload, once uploaded to a temp folder overwrite the existing database - El Forum - 03-24-2013 [eluser]TheFuzzy0ne[/eluser] You've lost me... However you're building your insert array, you just need to loop through the values and replace any single quotes with two single quotes. You need to decide how you're going to pragmatically insert your data into the database. Once you've figured that out, post back with what you have, and we'll see what we can do. CSV upload, once uploaded to a temp folder overwrite the existing database - El Forum - 03-24-2013 [eluser]the_unforgiven[/eluser] Well this is what i have at present and works just fine, except it throws SQL error because there's some apostrophes in the content Code: $data = file_get_contents("http://localhost/sussex/assets/uploads/wc_program.csv"); CSV upload, once uploaded to a temp folder overwrite the existing database - El Forum - 03-24-2013 [eluser]TheFuzzy0ne[/eluser] This is untested, but should work. I've made a few improvements by removing some the redundant code (the first two lines), and now your insert is made in a single query, rather than hitting the database once per insert. Code: // The start of the insert string. We just add to this with our loop. It could probably do with being tweaked a bit more, but I'll leave that to you. ![]() |