[lug] (OT) postgresql

Bear Giles bgiles at coyotesong.com
Mon Nov 11 18:00:25 MST 2002


> $result = $conn->exec("INSERT INTO cust1 VALUES((select 
> nextval('new_num')), '$date', '$in{x_method}', $quanity, '@array', 
> $ship_cost, $insure, $cost_less_ship, $total, '$in{x_first_name}', 
> '$in{x_last_name}', '$in{x_address}', '$in{x_city}', '$in{x_state}', 
> $in{x_zip}, '$in{x_country}', '$in{x_phone}', '$in{x_email}', 
> '$in{x_ship_to_first_name}', '$in{x_ship_to_last_name}', 
> '$in{x_ship_to_address}', '$in{x_ship_to_city}', '$in{x_ship_to_state}', 
> $in{x_ship_to_zip}, '$in{x_ship_to_country}')");

As an aside, it's common to store addresses in their own table.  This 
makes it easy to get default values for the forms, etc.

Something like:

create table addresses (
    id      int not null unique,  // set with sequence
    addr1   varchar(60) not null,
    addr2   varchar(60),
    city    varchar(60) not null,
    state   varchar(2) not null references states(country,state),
    zip     varchar(10),
    country varchar(10) not null references countries(country)
);

where there are a couple foreign keys to make sure the state and country 
are valid.  You could do the same thing with zip codes (remembering that 
Canadian and European codes look nothing like our all-numeric codes), or 
  check them with in insertion and update trigger.




More information about the LUG mailing list