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
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?

Link to comment
Share on other sites

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";

Link to comment
Share on other sites

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.