Page 1 of 1

INSERT problems, probably Foreign Key issues

Posted: Wed Dec 18, 2002 10:55 am
by jay_kay8
I have 2 tables:

users
filemanager=# create table users
filemanager-# (uid SERIAL,
filemanager(# username varchar(50),
filemanager(# password varchar(50),
filemanager(# accesslevel integer,
filemanager(# PRIMARY KEY (uid)
filemanager(# );

directories
filemanager=# create table directories
filemanager-# (directoryid SERIAL,
filemanager(# directoryname varchar(50),
filemanager(# datecreated datetime,
filemanager(# uid integer,
filemanager(# PRIMARY KEY (directoryid),
filemanager(# FOREIGN KEY (uid) REFERENCES users(uid));

I am trying to Insert information from a user front end into the directories table, specifically, I am attempting to insert data into the uid field, and that is where I am getting the following error:

Warning: pg_last_error(): 1 is not a valid PostgreSQL link resource in /usr/local/www/data-dist/filemanager/makedir.php on line 81
Error in query: INSERT INTO directories (directoryname,datecreated,uid) VALUES (hello,now(),1) .


Can anyone help? As I understand I cannot insert into the directories table until I have checked that the constraint is true, is that correct? I await replies :D

Posted: Wed Dec 18, 2002 2:01 pm
by BDKR
To me, it just looks the syntax is bunged up!
INSERT INTO directories (directoryname,datecreated,uid) VALUES (hello,now(),1)
That 'hello' needs quotes around it doesn't it?
INSERT INTO directories (directoryname,datecreated,uid) VALUES ('hello', now(), 1)
See if that works.

Cheers,
BDKR

Posted: Thu Dec 19, 2002 3:14 am
by jay_kay8
I see what you mean but that isn't what it's erroring about.
It's erroring on the Foreign Key insertion and I can't work out why. I am inserting a valid foreign key as the value is coming directly from a session which contains the users id, which is set using the primary key from the users table. Is it something to do with the constraints and if so, where should I check for it?

PHP bugs

Posted: Thu Dec 19, 2002 5:31 am
by jay_kay8
Have found an answer to my problems:

http://p2p.wrox.com/archive/pro_php/2000-12/11.asp

Might be worth a read if you're interested in PHP bugs