CSV upload poblems

I have a problem where a script, written in php, gets data from a csv file and puts that data in table columns in mysql. Most seems to work fine but some rows get cut off and the rest of that row then appears on the next row in the table. How can I stop this from happening? Is it some sort of termination problem?

my code:

//open the file 
$handle = fopen("test.csv", "r"); 

//get the data from each line of the file 
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { 

	$column10_replacements = array("'"=>"'");
    //get the data from that row 
    $column1 = $data[0]; 
    $column2 = $data[1];
	$column3 = $data[2];
	$column4 = $data[3];
	$column5 = $data[4];
	$column6 = $data[5];
	$column7 = $data[6];
	$column8 = $data[7];
	$column9 = $data[8];
	$column10 = $data[9];
	$column11 = $data[10];
	$column12 = $data[11];
	$column13 = $data[12];
	$column14 = $data[13];
	$column15 = $data[14];
	$column16 = $data[15];
	$column17 = $data[16];
	$column18 = $data[17];
	$column19 = $data[18];
	$column20 = $data[19];
	$column21 = $data[20];
	$column22 = $data[21];
	$column23 = $data[22];
	$column24 = $data[23];
	$column25 = $data[24];
	$column26 = $data[25];
	$column27 = $data[26];
	$column28 = $data[27];
	$column29 = $data[28];
	$column10_ammended=strtr($column10, $column10_replacements); 

    //put it into the database 
   $query = "REPLACE INTO `test` (`merchant_name`, `aw_thumb_url`, `aw_product_id`, `brand_name`, `product_name`, `description`, `category_id`, `category_name`, `merchant_category`, `aw_deep_link`, `aw_image_url`, `search_price`, `delivery_cost`, `merchant_deep_link`, `ean`, `in_stock`, `model_number`, `promotional_text`, `upc`, `specifications`, `mpn`, `delivery_time`, `pre_order`, `rrp_price`, `store_price`, `product_type`, `valid_to`, `valid_from`, `web_offer`) VALUES ( '$column2', '$column3', '$column4', '$column6', '$column7', '$column8', '$column9', '$column10_ammended', '$column11', '$column12', '$column13', '$column14', '$column15', '$column16', '$column17', '$column18', '$column19', '$column20', '$column21', '$column22', '$column23', '$column24', '$column25', '$column26', '$column27', '$column28', '$column30', '$column31', '$column32')";
   mysql_query($query) or die("<b>Data could not be entered</b>.\
<br />Query: " . $query . "<br />\
Error: (" . mysql_errno() . ") " . mysql_error());

//close the file 

Anyone else had this problem and found a fix?

Common wisdom would dictate you:

Find out on which line of your csv your insert is choking.
Isolate that line and find out which character(s) causes this problem.
Escape it properly so that it will insert into your database

Either come back and show us that line, or create a function which simply removes the offending character.

Likely you are going to find a few though because you don’t appear to be escaping the data before inserting it, eg with mysql_real_escape_string(). That could be a real security hole for you if there was something bad in that csv file.