Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Importing and Replacing SQL Table data using CSV

Hi, all, I need to create a PHP driven page in which my users can easily upload a .csv or other spreadsheet file to a database. I've set up a database in SQL, imported that data via mySQL, and successfully written PHP to display it in a wordpress site. Basically this is an inventory list, so my columns "quantity" will most often need to be updated, but they'll also be occassionally deleting rows when something's gone, so I don't know if it's best to replace the whole table upon upload.

But I'm stuck on how to write a file that will basically be a submission form to upload a fresh CSV file and have it interface replace data in my table.

Is there a good tutorial (or specific lesson) that would help me do this, or does anyone have experience who can walk me through? I've done a series of tutorials on the internet but can't quite get it working, and I'm getting irritated with myself!

4 Answers

Hi

I have some php knowledge so I'll try and help seeing as nobody else is :) I'm not quite sure I understand fully what your trying to do. Do you want the process to flow like this? User uploads CSV if there is already data in the database it drops that data and inserts the data from the csv.

Yes, that's probably easiest. I'd like the user to be able to upload the csv from a webpage instead of from MySQL, and my problem seems to me making that connection work.

Iam unsure but just begin this tut yesterday to understand more about databases/structure http://teamtreehouse.com/library/database-foundations

Sorry for the delay,

This stack overflow article talks about what I think your trying to do http://stackoverflow.com/questions/11448307/importing-csv-data-using-php-mysql If you have any questions about it let me know. It looks like that you will need to upload the csv file and execute it. Please note that when allowing users to upload php always insure that the directory they are uploading to is not web facing.