[php]<?php
$dbhost = ‘localhost’;
$dbuser = ‘xxxx’;
$dbpass = ‘xxxxx’;
$dbname = ‘survey’;
$dblink = mysql_connect($dbhost, $dbuser, $dbpass, $dbname);
mysql_select_db($dbname, $dblink);
$csvfile = “survey.csv”;
$seperator = “|”;
$lines = file($csvfile);
foreach($lines as $line) {
$rows = explode($seperator,$line);
echo “
”;”;
print_r($rows);
echo “
//exit;
$check = mysql_query(“SELECT token
FROM lime_tokens_67937
WHERE token
= ‘$uniquecsvfield1’ AND attribute_2
= $uniquecsvfield2 LIMIT 1”);
if(mysql_query($check) == 0) //If no rows are returned
$sql=(“INSERT INTO lime_tokens_67937 set
firstname=’”.$rows[2]."’,
lastname=’".$rows[3]."’,
token=’".$rows[4]."’,
validfrom=’".date(‘Y-m-d’)."’,
validuntil=’".date(‘Y-m-d’, strtotime(’+30 days’))."’
attribute_1=’".$rows[4]."’,
attribute_2=’".$rows[5]."’,
attribute_3=’".$rows[6]."’,
attribute_4=’".$rows[7]."’,
attribute_5=’".$rows[8]."’,
attribute_6=’".$rows[1]."’")
or die("Insert Error: ".mysql_error());
echo $sql ;
$result = mysql_query($sql, $dblink);
}
//@unlink($csvfile);
?>[/php]
This is the output from the echo
Array
(
[0] => 39550
[1] => TONY SANTANGELI
[2] =>
[3] =>
[4] => 01011011043087
[5] => 12/06/11
[6] => 303
[7] => DRASKO S
[8] => .00
[9] =>
)
INSERT INTO tokens set firstname=' ', lastname=' ', token='01011011043087 ', validfrom='2011-12-06', validuntil='2012-01-05' attribute_1='01011011043087 ', attribute_2='12/06/11', attribute_3='303 ', attribute_4='DRASKO S ', attribute_5=' .00', attribute_6='TONY SANTANGELI '
But it never gets inserted in to the database. I’m pulling what little hair I have left been looking at this for a week now and can’t see where I screwed up. This is my first php code attempt any help you can offer would be great or just tell me I’m stupid for missing some thing that is under my nose works too! ???
TANKS A BILLION!