I have two tables users and lead_contacts which have similar data. When somebody buys a product they become a user. How should I modify the two create staements below so:
- that the leads table receives a new entry with first_name, last_name, company and email, when a user is created.
the first_name, last_name, company and email in users table is updated automatically when the leads table info is changed
CREATE TABLE
lead_contacts
(
contact_id
int(11) NOT NULL auto_increment,
user_id
int(11) unsigned NOT NULL default '0',
email
varchar(100) NOT NULL default '',
company
varchar(50) NOT NULL default '',
first_name
varchar(50) NOT NULL default '',
last_name
varchar(50) NOT NULL default '',
address
varchar(100) NOT NULL default '',
address_2
varchar(100) NOT NULL default '',
city
varchar(50) NOT NULL default '',
state
varchar(50) NOT NULL default '',
country
varchar(50) NOT NULL default '',
postal_code
varchar(30) NOT NULL default '',
phone
varchar(30) NOT NULL default '',
fax
varchar(30) NOT NULL default '',
ship_bill_same
enum('Y', 'N') NOT NULL default 'Y',
notes
text NOT NULL,
admin_notes
text NOT NULL,
list_name
varchar(50) NOT NULL default '',
lead_list
int(11) unsigned NOT NULL default '0',
is_master_list
enum('N', 'Y') NOT NULL default 'N',
active_work
enum('Y', 'N') NOT NULL default 'Y',
parentID
int(11) unsigned NOT NULL default '0',
PRIMARY KEY (contact_id
),
KEYuser_id
(user_id
),
KEYlead_list
(lead_list
),
KEYis_master_list
(is_master_list
),
KEYactive_work
(active_work
),
KEYparentID
(parentID
)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 PACK_KEYS=1;CREATE TABLE
users
(
userID
int(11) NOT NULL auto_increment,
access_level
int(11) NOT NULL default '0',
username
varchar(100) NOT NULL default '',
password
varchar(100) NOT NULL default '',
first_name
varchar(50) NOT NULL default '',
last_name
varchar(50) NOT NULL default '',
company
varchar(100) NOT NULL default '',
email
varchar(100) NOT NULL default '',
PRIMARY KEY (userID
),
UNIQUE KEYusername
(username
)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ;