[PHP-DEV] PHP 4.0 Bug #8101 Updated: mysql_insert_id From: sniper <email protected>
Date: 01/30/01

ID: 8101
Updated by: sniper
Reported By: tetherow <email protected>
Old-Status: Feedback
Status: Closed
Bug Type: MySQL related
Assigned To:
Comments:

No feedback and an user error.

--Jani

Previous Comments:
---------------------------------------------------------------------------

[2000-12-07 18:31:15] sniper <email protected>
Why do you have the 'id' in your SQL line? You don't need to mention
it at all, it's 'auto_increment'. ie. it will be automatically incremented.

Try leaving it out. mysql_insert_id() should work then.

--Jani

---------------------------------------------------------------------------

[2000-12-07 10:47:39] tetherow <email protected>
mysql> show columns from staff;
+-----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+----------------+
| id | int(11) | | PRI | NULL | auto_increment |
| firstname | varchar(80) | YES | | NULL | |
| lastname | varchar(80) | YES | | NULL | |
| title | varchar(80) | YES | | NULL | |
| phone | varchar(15) | YES | | NULL | |
| cell | varchar(15) | YES | | NULL | |
| home | varchar(15) | YES | | NULL | |
| pager | varchar(60) | YES | | NULL | |
| email | varchar(30) | YES | | NULL | |
| username | varchar(16) | YES | | NULL | |
| password | varchar(16) | YES | | NULL | |
| epassword | varchar(16) | YES | | NULL | |
| company | int(11) | YES | | NULL | |
| role | varchar(80) | YES | | NULL | |
| other | varchar(15) | YES | | NULL | |
| active | tinyint(4) | YES | | NULL | |
| shell | varchar(128) | YES | | NULL | |
| forward | varchar(64) | YES | | NULL | |
| disporder | int(11) | YES | | NULL | |
+-----------+--------------+------+-----+---------+----------------+

 $query="insert into staff (id, firstname, lastname, title, phone, cell, home, pager, email, username, password, epassword, company, role, other, active, shell, forward, disporder) values (NULL, '$this->firstname', '$this->lastname', '$this->title', '$this->phone', '$this->cell', '$this->home', '$this->pager', '$this->email', '$this->username', '$this->password', '$this->epassword', '$this->company', '$this->role', '$this->other', '1', '$this->shell', '', $this->disporder)";
 $cursor=mysql_db_query('staff', $query, $connection);
                // Need to check return here.
                $this->id=mysql_insert_id($connection);
echo "Connection: $connection<br>nID: $this->id<br>n";

When run $connection is set to a valid resource and $this->id is 0.

The data does get inserted into the database without any problems so I know the query is good.

I looked at the page referenced and the auto_increment field is a standard int field. The LAST_INSERT_ID() function appears to work but am curious as to why the mysql_insert_id does not.

---------------------------------------------------------------------------

[2000-12-05 08:25:32] sniper <email protected>
What is the table like in which your query inserts data?
And what is the query like?
And have you read the following page?

http://www.php.net/manual/function.mysql-insert-id.php

--Jani

---------------------------------------------------------------------------

[2000-12-04 14:23:14] tetherow <email protected>
MySQL insert_id function returns 0 on valid insert.

Using PHP 4.0.3pl1 and MySQL 3.23.28gamma.
configured using --with-mysql=/usr/local

$connection=mysql_pconnect($server, $username, $password);
$cursor=mysql_db_query('staff', $query, $connection);
$id=mysql_insert_id();
have also tried
$id=mysql_insert_id($connection)

In both instances $id is 0 yet the insert does succeed.

---------------------------------------------------------------------------

Full Bug description available at: http://bugs.php.net/?id=8101

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: php-dev-unsubscribe <email protected>
For additional commands, e-mail: php-dev-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>