Received: from visi.net (arsenal.visi.net [206.246.194.60]) by postgresql.org (Postfix) with ESMTP id C1DC4475852 for ; Thu, 25 Apr 2002 16:35:21 -0400 (EDT) Received: from [216.54.6.254] (HELO localhost.localdomain) by visi.net (CommuniGate Pro SMTP 3.5.6) with ESMTP id 25685844; Thu, 25 Apr 2002 16:34:03 -0400 Subject: Re: id field error From: Jeff Self To: angelo.rigo@globo.com Cc: pgsql-php@postgresql.org In-Reply-To: <3CC7A89800004414@nplex.globo.com> References: <3CC7A89800004414@nplex.globo.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Mailer: Ximian Evolution 1.0.3 Date: 25 Apr 2002 16:34:35 -0400 Message-Id: <1019766876.29436.26.camel@jselfpc> Mime-Version: 1.0 X-Archive-Number: 200204/94 X-Sequence-Number: 1118 On Thu, 2002-04-25 at 16:00, angelo.rigo@globo.com wrote: > Hi ! > I=B4m doing my first publishing system for a last aquired boooks for a li= brary. >=20 > the problem begin in the id field, wich i choose to be primary key and un= ique. > i could just insert data one time the others give me this error: >=20 > Cannot insert a duplicate key into unique index biblioteca_pkey >=20 > i use this piece of code below to insert the data: >=20 > $query =3D "INSERT INTO biblioteca (id, autor, titulo, editora) values ('= $id', > '$autor', '$titulo', '$editora')"; > $result =3D pg_exec($db, $query); >=20 > may i can alter the id collumn and the query to insert the data anybody > knows what exactly to do ? >=20 > Thank=B4s >=20 > =C2ngelo >=20 Design your table so that id is of type serial. This lets it auto-increment the idea. Then do this: $query =3D "INSERT INTO biblioteca (autor, titulo, editora) values ('$autor', '$titulo', '$editora')"; $result =3D pg_exec($db, $query); --=20 Jeff Self Information Technology Analyst Department of Personnel City of Newport News 2400 Washington Ave. Newport News, VA 23607 757-926-6930