Re: id field error

From: Jeff Self <jself(at)nngov(dot)com>
To: angelo(dot)rigo(at)globo(dot)com
Cc: pgsql-php(at)postgresql(dot)org
Subject: Re: id field error
Date: 2002-04-25 20:34:35
Message-ID: 1019766876.29436.26.camel@jselfpc
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

On Thu, 2002-04-25 at 16:00, angelo(dot)rigo(at)globo(dot)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

In response to

Browse pgsql-php by date

  From Date Subject
Next Message Surojit Niyogi 2002-04-26 22:05:26 Re: id field error
Previous Message angelo.rigo 2002-04-25 20:00:04 id field error