Jump to content

str replace double comma


flemingmike

Recommended Posts

hi, i have a script that inserts a csv into mysql.  i run into errors when there is an empty field

 

example:

 

filed1,field2,field3,,field5,,field7

 

here is my code that processes it.

 

	$handle = fopen("uploads/$filename", "r");	

while(($data = fgetcsv($handle, 1000, ",")) !== FALSE)      {



$import .= "INSERT into goaliestats(id,name,gp,w,so,gaa,date) values(NULL,'$data[0]','$data[2]','$data[8]','$data[26]','$data[18]','$data[28]')" . "\n";

mysql_query($import) or die(mysql_error());
}


fclose($handle);

 

 

is there a way i can make a ,, into ,0,

 

?

 

thanks!

Link to comment
https://forums.phpfreaks.com/topic/248175-str-replace-double-comma/
Share on other sites

nevermind.  this isnt my problem.

 

ime getting an error

Notice: Undefined variable: import in E:\Website\hockeypool\admin\import.php on line 31
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 'INSERT into goaliestats(id,name,gp,w,so,gaa,date) values(NULL,'Carey Price','72'' at line 2

 

this is the line thats having the error:

 

Carey Price,VAN,72,,60,,3590,,38,,15,,7,,3,,126,,2.11,,1753,,1627,,0.928,,4,,9/29/2011

 

any ideas on this?

You are trying to append the SQL string to the $import variable that isnt defined. Remove the fullstop before your = sign and your error should be fixed.

$import = "INSERT into goaliestats(id,name,gp,w,so,gaa,date) values(NULL,'$data[0]','$data[2]','$data[8]','$data[26]','$data[18]','$data[28]')" . "\n";

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.