INSERT problems, probably Foreign Key issues

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
jay_kay8
Forum Newbie
Posts: 6
Joined: Wed Dec 18, 2002 10:55 am
Location: London, UK

INSERT problems, probably Foreign Key issues

Post 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
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post 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
jay_kay8
Forum Newbie
Posts: 6
Joined: Wed Dec 18, 2002 10:55 am
Location: London, UK

Post 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?
jay_kay8
Forum Newbie
Posts: 6
Joined: Wed Dec 18, 2002 10:55 am
Location: London, UK

PHP bugs

Post 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
Post Reply