pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jeff Self <jself@nngov.com>
To: angelo.rigo@globo.com
Cc: pgsql-php@postgresql.org
Subject: Re: id field error
Date: 25 Apr 2002 16:34:35 -0400
Message-ID: <1019766876.29436.26.camel@jselfpc> (raw)
In-Reply-To: <3CC7A89800004414@nplex.globo.com>
References: <3CC7A89800004414@nplex.globo.com>

On Thu, 2002-04-25 at 16:00, angelo.rigo@globo.com wrote:
> Hi !
> I´m doing my first publishing system for a last aquired boooks for a library.
> 
> the problem begin in the id field, wich i choose to be primary key and unique.
> i could just insert data one time the others give me this error:
> 
>  Cannot insert a duplicate key into unique index biblioteca_pkey
> 
> i use this piece of code below to insert the data:
> 
> $query = "INSERT INTO biblioteca (id, autor, titulo, editora) values ('$id',
> '$autor', '$titulo', '$editora')";
> $result = pg_exec($db, $query);
> 
> may i can alter the id collumn and the query to insert the data anybody
> knows what exactly to do ?
> 
> Thank´s
> 
> Ângelo
> 

Design your table so that id is of type serial. This lets it
auto-increment the idea. Then do this:

$query = "INSERT INTO biblioteca (autor, titulo, editora)
	values ('$autor', '$titulo', '$editora')";
$result = pg_exec($db, $query);

-- 
Jeff Self
Information Technology Analyst
Department of Personnel
City of Newport News
2400 Washington Ave.
Newport News, VA 23607
757-926-6930




view thread (4+ messages)  latest in thread

Message-ID: <1019766876.29436.26.camel@jselfpc>
Permalink:  ../1019766876.29436.26.camel@jselfpc/
Also on:    postgresql.org/message-id/1019766876.29436.26.camel@jselfpc

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: jself@nngov.com, angelo.rigo@globo.com
  Subject: Re: id field error
  In-Reply-To: <1019766876.29436.26.camel@jselfpc>
  References: <3CC7A89800004414@nplex.globo.com> <1019766876.29436.26.camel@jselfpc>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox