$dbcnx = @mysql_connect('mysql.plainhost.com', 'ecosmar_ecosmart', 'ecoman1');
mysql_select_db('ecosmar_products', $dbcnx);
$dtnum = date(Ymd)*1;
$outage = $_POST[outage];
$newthem = $_POST[newthem];
$newthe = array_shift($newthem);
$countthem = count($newthem);
$countyes = 0;
foreach($newthem as $value){
$gem = explode('|', $value);
$chk = mysql_query("SELECT * FROM ship WHERE item='$gem[0]'");
if(!$chk){
echo(" Something is wrong. Cannot check for duplicate. ".mysql_error()." ");
}else{
$rochk = mysql_fetch_array($chk);
if($rochk[0] == ""){
if($gem[0] != ""){
$into = mysql_query("INSERT INTO ship SET item='$gem[0]',sku='$gem[1]',upc='$gem[2]',carrier='$gem[3]',crr_phone='$gem[4]',crr_account='$gem[5]',class='$gem[6]',o_city='$gem[7]',o_country='$gem[8]',o_code='$gem[9]',unit='$gem[10]',weight_lbs='$gem[11]',height_in='$gem[12]',width_in='$gem[13]',length_in='$gem[14]',custom='$gem[15]',currency='$gem[16]',minimum='$gem[17]',handling='$gem[18]',flat='$gem[19]',rate_1='$gem[20]',rate_wgt_1='$gem[21]',rate_2='$gem[22]',rate_wgt_2='$gem[23]',rate_3='$gem[24]',rate_wgt_3='$gem[25]',up_date='$dtnum',description='$gem[27]'");
if(!$into){
echo("Could not insert new row for $gem[0] ".mysql_error()." ");
}else{
$countyes = $countyes + 1;
}
}else{
$countyes = $countyes + 1;
}
}elseif($rochk[0] != ""){
$result = array_diff_assoc($rochk, $gem);
if(empty($result)){
$countyes = $countyes + 1;
}else{
$uppit = mysql_query("UPDATE ship SET sku='$gem[1]',upc='$gem[2]',carrier='$gem[3]',crr_phone='$gem[4]',crr_account='$gem[5]',class='$gem[6]',o_city='$gem[7]',o_country='$gem[8]',o_code='$gem[9]',unit='$gem[10]',weight_lbs='$gem[11]',height_in='$gem[12]',width_in='$gem[13]',length_in='$gem[14]',custom='$gem[15]',currency='$gem[16]',minimum='$gem[17]',handling='$gem[18]',flat='$gem[19]',rate_1='$gem[20]',rate_wgt_1='$gem[21]',rate_2='$gem[22]',rate_wgt_2='$gem[23]',rate_3='$gem[24]',rate_wgt_3='$gem[25]',up_date='$dtnum',description='$gem[27]' WHERE item='$gem[0]'");
if(!$uppit){
echo("Could not update $gem[0] ".mysql_error()." ");
}else{
$countyes = $countyes + 1;
}
}
}
}
}//4each
if(!empty($outage)){
foreach($outage as $value){
$out = mysql_query("DELETE FROM ship WHERE item='$value' LIMIT 1");
if(!out){
echo("Could not delete ".$value." ".mysql_error()." ");
}else{
echo("$value Deleted, ");
}
}//4ea
$sql = mysql_query("OPTIMIZE TABLE 'ship'");
if($sql){
echo("Data Base Optimization Complete.");
}
}
if($countthem == $countyes){
echo("Successful Update of Shipping Table. ");
}else{
echo("Problems Overwriting Shipping Table. ");
}
?>
|