Jump to content

Recommended Posts

Hello.

 

I am uploading a csv file and populating a data base. I have tried all kinds of things to get the header removed from the input but it either stops writing all together or breaks. Can anyone help me or does anyone have any suggestions? It works pretty good as intended now except for the one header record that gets added.

 

Here is my script:

 

 

<?php
include '_inc/include.php';
if ($_FILES[csv][size] > 0) {
//get the csv file
$file = $_FILES[csv][tmp_name];
$handle = fopen($file,"r");
//loop through the csv file and insert into database
do {
 if ($data[0]) {
	 $mysql_query = mysql_query("INSERT INTO carbon_PA (closeddate, soldprice, streetnumber, streetname, streetsuffix, city, state, zip, gla, built, acres, taxid, photo, dom) VALUES
		 (
			 '".addslashes($data[0])."',
			 '".addslashes($data[1])."',
			 '".addslashes($data[2])."',
			 '".addslashes($data[3])."',
			 '".addslashes($data[4])."',
			 '".addslashes($data[5])."',
			 '".addslashes($data[6])."',
			 '".addslashes($data[7])."',
			 '".addslashes($data[8])."',
			 '".addslashes($data[9])."',
			 '".addslashes($data[10])."',
			 '".addslashes($data[11])."',
			 '".addslashes($data[12])."',
			 '".addslashes($data[13])."'
		 )
	 ");
 }
} while ($data = fgetcsv($handle,10000,",","'"));
//
//redirect

}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Import a CSV File with PHP & MySQL</title>
</head>
<body>
<?php if (!empty($_GET[success])) { echo "<b>Your file has been imported by import 55.</b><br><br>"; } //generic success notice ?>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
Choose your file: <br />
<input name="csv" type="file" id="csv" />
<input type="submit" name="Submit" value="Submit" />
</form>
<P> Display Data Contents <a href ='Data-Display.php'>here</a></P>
</body>
</html>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.