Re: INSERT to auto_increment field
| From: | NoWhErEMan | Date: | Sat, 24 Aug 2002 11:53:02 +0000 |
| Subject: | Re: INSERT to auto_increment field | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-21339@lists.php.net to get a copy of this message | ||
problem solved, my mistake
"Nowhereman" <vckh@yahoo.com> ¼¶¼g©ó¶l¥ó·s»D
:20020824110554.94594.qmail@pb1.pair.com...
> Hi all,
>
> i have 2 column in a table
keyword
> query_id: int, not null, primary, auto_increment
> keyword: text
>
> I want to insert a keyword "abc" into the table, in php
>
> $mysqlquery = "INSERT INTO keyword (query_id, keyword) VALUES (NULL,
> '$_GET[query]')";
> $result = mysql_query($mysqlquery) or die(mysql_error());
>
> it show error "Column 'query_id' cannot be null"
>
> i also tried:
> $mysqlquery = "INSERT INTO keyword (keyword) VALUES ('$_GET[query]')";
> $result = mysql_query($mysqlquery) or die(mysql_error());
> it shown errror
> "Duplicate entry '0' for key 1"
> How i expect is mysql would auto generate a auto_increment key to the row,
> but it doesn;t
>
> I think the problem is related to the auto_increment field
> How can i get the correct value for the auto_increment?
> I know i can get the previous auto_increment value by query MAX(query_id)
> But is there a more clever way to do it in one query?
>
> Thanks in advance
> Nowhereman
>
>