Been up way too long looking at this project. For some reason, quotes really hang me up. I stare at them and then they're right and then they're wrong, especially since there's a deadline. I seem to get dyslexic when I'm tired.
Enough! Here's the issue I'd be grateful for help on:
Have a tab delmited list exported from an excel file. The first field is the key, which is intentionally left blank so MySQL can auto increment the value and insert.
The script below isn't picking up the initial tab in each row, so I'm returning a mismatched column error.
Since the tab is the first field in the row, I was thinking to just add the correct quotes and not even bother with the first field in the excel file - just eliminate the entire column from the file that gets converted to tab delimited text.
Can anyone spot where I've gone wrong with the leading tab? If not, can you help me parse the line so that I can just insert it - by adding the right combination of quotes?
I tried adding NULL as a value to all of the first column, but I get an error for a duplicate entry.
Duplicate entry '0' for key 1
So I know I want to change this line:
$sql = "insert into uploaded values ('".
implode("','", $arr) ."')";
Only now I've looked at it so much that I'm all dyslexic about the quotes.
for($i=0; $i<sizeof($fcontents); $i++) {
$line = trim($fcontents[$i]);
$arr = explode("\t", $line);
#if your data is comma separated
# instead of tab separated,
# change the '\t' above to ','
// insert into TABLE
$sql = "insert into uploaded values ('".
implode("','", $arr) ."')";
mysql_query($sql);
echo $sql ."<br>\n";
if(mysql_error()) {
echo mysql_error() ."<br>\n";
}
Any help would be greatly appreciated.
Thanks,
Lee