Quote:
Originally Posted by freecrm
Thanks Guys..
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... 
|
Try just above '//define column values':
$value=explode(",",$value);
and changing $arrfile=explode(",", ...
to $arrfile=explode("\n", ...
and it's worth trying to understand at least some of the php docs, at least after a little experience. It can take you far!
Good luck!