[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-general
Subject:    RE: [PHP] doing auto number myself to a primary key...
From:       "John W. Holmes" <holmes072000 () charter ! net>
Date:       2003-01-31 23:14:20
[Download RAW message or body]

>      $sql="SELECT TOP(id) FROM divxtemp";
>      $res=mysql_db_query("DB",$sql) or die (mysql_error());
>      $reg=mysql_fetch_array($res);
>      $id=$reg["id"]+1;
>      $sql="INSERT INTO divxtemp (titulo,cds,id) VALUES
> ('$titulotxt','$cdstxt','$id')";
>      mysql_db_query("DB",$sql) or die (mysql_error());
> 
> the id is always 1 so he can't save duplicate keys...

I hope you having some locking around where you select the ID and then
insert it... otherwise you're asking for trouble.

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/

PS: You're problem is $reg["id"]+1 should be $reg["TOP(id)"]+1 or use AS
in your query: SELECT TOP(id) AS id ...



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic