IT is much easier to understand. Thanks so much. I don't want to use the sql upload. I don't want it to break for some unseen reason on the user. I think I almost have it except the values don't get inserted? I'm not quite sure on array_map. It takes the imploded string and makes it an array again? I will however never use csv format again only text tab delimited. I see what implode does it puts the "," between the array pieces. I just noticed it doesn't have single qutoes ' ' around the first value in the $hdr .
-----error----------
Invalid query:Column count doesn't match value count at row 1
INSERT INTO mydb.inventory (control_id, bu, cart_id, accountNo,zonenm,zoneid,sku,supplierName,ndc,brandDescription,genericDescription,class,qty,unit) VALUES (222, '0005', '111111',Array)
if (($fh = fopen($target_path, 'r+')) !== FALSE ){
while (($res = fgetcsv($fh, ",")) !== FALSE) {
if ($row==1 ){
$hdr = implode(',', $res);
I thought maybe I need to put implode into the else to build the values so I tried that also but got the same error:
[code=php]
if (($fh = fopen($target_path, 'r+')) !== FALSE ){
while (($res = fgetcsv($fh, ",")) !== FALSE) {
if ($row==1 ){
$hdr = implode(',', $res);
}else{
$sData= implode(',', $res);
$sData = array_map('mysql_real_escape_string', $sData);
// echo "<b>" . $sData . "</b><br />";
// $sData=substr($sData,1);
$sql="INSERT INTO mydb.inventory (control_id, bu, cart_id, $hdr) VALUES ($controlID, '$bu', '$cart_id',$res) ";
echo "$sql<br /> ";
$result=mysql_query($sql);
//die($sql);
if ( !$result ) {die("<font color='red'>Invalid query:</font>" . mysql_error() . "<br>$sql");}
}//END ELSE
$row++ ;
}else{
$res = array_map('mysql_real_escape_string', $res);
// echo "<b>" . $sData . "</b><br />";
// $sData=substr($sData,1);
$sql="INSERT INTO mydb.cart_inventory (control_id, bu, cart_id, $hdr) VALUES ($controlID, '$bu', '$cart_id',$res) ";
echo "$sql<br /> ";
[/code]
---2nd way--
Invalid query:Column count doesn't match value count at row 1
INSERT INTO mydb.inventory (control_id, bu, cart_id, accountNo,zonenm,zoneid,sku,supplierName,ndc,brandDescription,genericDescription,class,qty,unit) VALUES (225, '08005', '111111',Array)
by the way, thanks for all your help.