Problems on inserting two tables

From: Date: Mon, 22 Apr 2002 13:12:30 +0000
Subject: Problems on inserting two tables
Groups: php.db 
Request: Send a blank email to php-db+get-18723@lists.php.net to get a copy of this message
Using php & postgresql, I have 2 tables and a sequence as follows: create sequence serial; CREATE TABLE glmaster ( id int default nextval('serial'), accno char(6) constraint accno_con not null unique, reportlevel int, name text, isheader boolean default 'f', isdebit boolean not null, inactive boolean default 'f', primary key (id) ); CREATE TABLE glcheque ( id int references glmaster, primary key(id) ); My problem is this, when inserting to glmaster, at times I want to also insert the same value of id into glcheque. The values originate in a form generated using php. My first attempt was to insert all values except id into glmaster then followed by (in php): $sql = select id as glid from glmaster where accno = $glaccno; pg_exec($dbcon, $sql); then $sql1 = insert into glcheque values ($glid); etc that fails because $glid is not initialised. My next attempt was '$sql = select nextval ('serial') as glid;' etc Neither does this initialise $glid. I'm not sure if this is simply a timing problem, or if there is something wrong with my logic. Thanks for any help given Bob Parker

« previous php.db (#18723) next »