INSERT to auto_increment field

From: Date: Sat, 24 Aug 2002 11:06:17 +0000
Subject: INSERT to auto_increment field
Groups: php.db 
Request: Send a blank email to php-db+get-21337@lists.php.net to get a copy of this message
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

« previous php.db (#21337) next »