Original Post
hi, im working on a 2d online RPG. anyway, im setting up the login and character creation part of the game. i have 2 tables - a table which stores accounts, and a table which stores characters. here is what they look like: now, i can add accounts just fine. but im having a problem trying to add a character to an account. heres how i make an account:
CREATE TABLE T_AC_ACCOUNTS
(
AC_ID INT NOT NULL AUTO_INCREMENT,
USERNAME VARCHAR(20),
PASSWORD VARCHAR(20),
FIRST_NAME VARCHAR(50),
LAST_NAME VARCHAR(50),
EMAIL VARCHAR(150),
LAST_LOGIN TIMESTAMP,
UNIQUE (USERNAME),
PRIMARY KEY (AC_ID)
);
CREATE TABLE T_CH_CHARACTERS
(
CH_ID INT NOT NULL AUTO_INCREMENT,
CH_AC_ID INT,
NAME VARCHAR(30),
XPOS INT,
YPOS INT,
MAP_OCCUPIED VARCHAR(150),
FOREIGN KEY (CH_ID) REFERENCES T_AC_ACCOUNTS (AC_ID),
PRIMARY KEY (CH_ID)
);
INSERT INTO T_AC_ACCOUNTS (USERNAME,PASSWORD,FIRST_NAME,LAST_NAME,EMAIL)
VALUES ('some account','some pass','blah','bleeh','spam@me.com');
now that i have an account created, i'd like to add characters to this account. i do it like this:
INSERT INTO T_CH_CHARACTERS (ACCOUNT_ID,NAME,XPOS,YPOS,MAP_OCCUPIED)
VALUES (1,'some character',802,440,'somemap.map');
now, this works fine. however, when i try to add another character to the same account (has the same CH_AC_ID), then i get a foreign key violation. i'm not sure what im doing wrong, but i know its something obvious. please go easy on me, its 6:20 in the morning and i've been up all night coding. time to sleep now [smile]. thanks for any help.