Thanks Guys..
For starters, my file is a comma seperated values file as follows (Copied directly from notepad but with \n at new lines):
For ease of testing, this file is located at www.freecrm.x10hosting.com/testdata.csv
Code:
"FIRSTNAME","LASTNAME","COMPANY"\n
"Joe","Bloggs","Joe Bloggs Ltd"\n
"Jane","Bloggs","Joe Bloggs Ltd"\n
"John","Doe","John Doe Ltd"\n
My code now looks like this...
PHP Code:
//connect to db or show error
mysql_select_db($database_freecrm, $freecrm)
or die(mysql_error());
//if form hidden field returns a value, execute the following script
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
//allocate posted file path to variable
$file=$_POST['filepath'];
//load file and split into array
$arrfile = explode(',',file_get_contents($file));
//loop through each line
foreach($arrfile as $value){
//define column values
$firstname=value[1];
$lastname=value[2];
$company=value[3];
//insert into db
$insert="INSERT INTO TEST (FIRSTNAME, LASTNAME, COMPANY) VALUES ('$firstname','$lastname','$company')";
mysql_query($insert) OR die(mysql_error());
}
}
I have tried several versions of $something=$value[1] but I can't get it right. The square brackets are returning an error.
Code:
Parse error: syntax error, unexpected '[' in /home/freecrm/public_html/crmimexport/contactimport.php
I have tried with (), and without brackets but no difference.
Just one thing to bear in mind, field (column) 1 is an autoincrement Integer ID and not specified in the csv file.
I checked out the page on the php site but it's all gobbledegook to me!!! I would prefer to understand what I'm doing rather than just copy lines and lines of strange code...