I think you want this.

$sql = "INSERT INTO table (cod, nome, email) VALUES ('', '$nome',
'$email')";
$result = mysql_query($sql);
$cod = mysql_insert_id();

The $cod is the primery key.
Hope it helps.

Bruno Gimenes Pereti.

----- Original Message -----
From: "Matt Stewart" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, October 26, 2001 9:57 AM
Subject: [PHP-DB] getting results from INSERT


> What i'm after is getting the primary key for a record that's just been
> added - I have an image file upload accompanying a database addition, and
> the image gets renamed $unique_ID.jpeg
> only problem is that the current method inserts the information, which
auto
> produces the primary key, but the only way i know to extract that is by
> doing a SELECT, searching for all the matching values to the ones just
> entered, and if two entries are the same(except for the primary key -
which
> is unknown), the image will replace the earlier entry, rather than the one
i
> actually want it to be for. Is there a way of returning this primary key
> immediately after that record is created?
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to