Link to home
Start Free TrialLog in
Avatar of movieprodw
movieprodw

asked on

Bulk insert / update, remove ',' from a field

Hello,

I have the below codes and I want to remove any ,'s from the field before it inserts into the db. The fields are 'mileage' and 'price'


UPDATE
-----------

      $str_field_value="";
$allow = array( 'member_id', 'vid', 'listing_plan', 'status', 'date_listed', 'year', 'vehicle_location', 'make', 'model', 'model_id', 'price', 'ext_color', 'int_color', 'stock_number', 'vin', 'mileage', 'descint', 'desc2', 'engine_type', 'valves', 'cooling', 'max_horse', 'max_torque', 'top_speed', 'fuel_type', 'transmission', 'drive', 'seats', 'doors', 'weight', 'brakes', 'mpg_highway', 'mpg_city', 'tank_size' );
      foreach ( $_POST as $key => $value )
      {
            if( in_array( $key, $allow ))
            {
                  if($str_field_value!="")
                  {
                        $str_field_value.=",";
                  }
                 
                  $str_field_value.=mysql_real_escape_string( $key )."='".mysql_real_escape_string( $value )."'";
            }
      }

-----------------
AND INSERT
----------------


$allow = array( 'member_id', 'vid', 'listing_plan', 'status', 'date_listed', 'year', 'vehicle_location', 'make', 'model', 'model_id', 'price', 'ext_color', 'int_color', 'stock_number', 'vin', 'mileage', 'descint', 'desc2', 'engine_type', 'valves', 'cooling', 'max_horse', 'max_torque', 'top_speed', 'fuel_type', 'transmission', 'drive', 'seats', 'doors', 'weight', 'brakes', 'mpg_highway', 'mpg_city', 'tank_size' );

foreach ( $_POST as $key => $value )
{
  if ( in_array( $key, $allow ) )
  {
      $fields[] = mysql_real_escape_string( $key );
    $values[] = mysql_real_escape_string( $value );
  }
}


$sql = "INSERT INTO vehicle_data ( " . implode( ", ", $fields ) . " ) VALUES ( '" . implode( "', '", $values ) ."' ) ";
ASKER CERTIFIED SOLUTION
Avatar of kawzaki
kawzaki

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of movieprodw
movieprodw

ASKER

I will try that. Thanks!
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for your help,

I just 're-set' the post for that result and it worked great

ie
$_POST["mileage"] = str_replace(",","",$_POST["mileage"]);