I am adding a csv file upload script for my webid auction site.
I tested it outside the webid script in a simple test database and it worked fine.
I need to make some changes to it. It should catch the user's id and create an auto increment item id. For now I can't even get it to work.
I also don't know if it will work unless all the fields in the csv file have values as they will not, since this is for a bulk lister and not all of the users add data to every field.
Here is the site I downloaded it from
Help would be very appreciated. This will allow people to upload thousands of listings at once.
Okay I will post a list of the database fields and the code itself.
The fields in the table are


File Name: importCSV.php
File URI: http://k-fez.com/
Description: This scripts verifies that a CSV file has been upload via HTTP POST and then inserts all rows into a MySQL database.
Author: Kevin Pheasey
Author URI: http://k-fez.com/
Version: 1.0

/*  Copyright (C) 2010  Kevin Pheasey (email: kevin at k-fez.com)

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.


if($_FILES["file"]["type"] != "application/vnd.ms-excel"){
	die("This is not a CSV file.");
	//Connect to the database
	$dbhost = 'localhost';
	$dbuser = 'root';
	$dbname = 'webid';
	$link = mysql_connect($dbhost, $dbuser) or die('Error connecting to mysql server');
	//Process the CSV file
	$handle = fopen($_FILES['file']['tmp_name'], "r");
	$data = fgetcsv($handle, 1000, ","); //Remove if CSV file does not have column headings
	while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
		$att0 = mysql_real_escape_string($data[0]);
		$att1 = mysql_real_escape_string($data[1]);
		$att2 = mysql_real_escape_string($data[2]);
		$att3 = mysql_real_escape_string($data[3]);
		$att4 = mysql_real_escape_string($data[4]);
		$att5 = mysql_real_escape_string($data[5]);
		$att6 = mysql_real_escape_string($data[6]);
		$att7 = mysql_real_escape_string($data[7]);
		$sql = "INSERT INTO `webid_auctions` (
					`id` ,
					`user` ,
					`title` ,
					`subtitle` ,
					`starts` ,
					`description` ,
					`pict_url` ,
					`category` ,
					VALUES ('" . $att0 . "', '" . $att1 . "', '" . $att2 . "', '" . $att3 . "', '" . $att4 . "', '" . $att5 . "', '" . $att6 . "', '" . $att7 . "')";
	echo "CSV file successfully imported.";
	die("You shouldn't be here");


It doesn't upload anything into the database at this point, but shows the file was successfully uploaded message. I need also to fix the bugs I mentioned above. Thanks

Recommended Answers

All 4 Replies

Remove the comma after category in your insert query.

If you add error checking, you can find these mistakes very easily.

Still not working,

Remove the comma after category in your insert query.

If you add error checking, you can find these mistakes very easily.

Member Avatar

I notice: Author: Kevin Pheasey

Have you asked him about this?

I asked him. I never could fix it. It probably needs to have the primary key added in front of the data and it needs to capture the user id from the session and insert it.
It would be, id(primary key), user, title, subtitle

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.