Questions tagged [mysql-insert-id]

Retrieves the ID from the previous INSERT query on this database connection.

mysql_insert_id() is used to retrieve the ID from a previous INSERT query on this database connection.

The query must have been made to a table that has an auto_increment field - that is the field that will be returned.

You can pass in an optional parameter, which is the database connection to use; otherwise it will use the most recently opened database connection as a default.

Note that this function is connection-based - two separate processes invoking this function separately will create two separate connections to the database, which means that each process will return the correct ID for its own insert.

Note that as of PHP 5.5.0, this function has been deprecated.

124 questions
1
vote
4 answers

Call to mysql_insert_id gives warning

Hi I'm receiving this warning when trying to retrieve the insert id Warning: mysql_insert_id(): supplied argument is not a valid MySQL-Link resource in mysql_query($importword); $word_id = mysql_insert_id($importword);
acctman
  • 4,229
  • 30
  • 98
  • 142
1
vote
1 answer

Last Inserted respective Records Id from MySQL PHP

I'm having two MySQL Tables Customer and Address. I'm having data of a Complete Customer (i.e., Personal Info with Address) Table Structures Customer CustId FullName Gender …
B.Balamanigandan
  • 4,713
  • 11
  • 68
  • 130
1
vote
1 answer

CodeIgniter: I am occurring this database error 1048 on submitting registration form.

I am issuing this database error on localhost while submitting registration form that is while inserting user values into database. A Database Error Occurred Error Number: 1048 Column 'first_name' cannot be null INSERT INTO users(first_name,…
Hardik Patil
  • 515
  • 1
  • 4
  • 16
1
vote
1 answer

MySQL insert data AVOID Ambiguity

First of all, I want to INSERT data in two TABLE at a time. I know it is not possible. Due to this limitation, i foresee a problem that could occur if two REQUESTS(to insert data) simultaneously occur. Is there any way that when i INSERT data in…
Asif Mehmood
  • 964
  • 2
  • 14
  • 35
1
vote
1 answer

Php, MySql - Multiple DB connections and mysql_insert_id()

I have 2 database connections, and I want to get the last inserted ID from one of the connections. $old_database = mysql_connect('host', 'username', 'password'); mysql_select_db('database1', $old_database); $new_database = mysql_connect('host',…
coffeemonitor
  • 12,780
  • 34
  • 99
  • 149
1
vote
2 answers

can I trust mysql_insert_id() to return correct value, multithreading paranoia

I made a function that inserts a new line into a table, after calling an INSERT statement into mysql, I then make some checks, and then I check the value of mysql_insert_id(). I want to be quiet knowing that it is not possible for another thread to…
Ted
  • 3,805
  • 14
  • 56
  • 98
1
vote
0 answers

MySQL :: insert_id returning non zero value for a SELECT query

I've just spent the last 4 hours tracing a bug in my script. I kept receiving the following error: Call to a member function fetch_assoc on a non object This was being thrown when I did something like: $query = $database -> query("SELECT…
Keir Simmons
  • 1,634
  • 7
  • 21
  • 37
1
vote
2 answers

mysql_insert_id() is returning 0

I've looked through the various answers and none of them seem to be helping. I have a simple Insert Query that is working as expected. Nothing special $user_account_query = mysqli_query($dbc," INSERT INTO ACCOUNT (EMAIL, IS_OPEN) …
Alex
  • 542
  • 5
  • 24
1
vote
2 answers

Do you use mysql_error($con) or mysql_insert_id($con) to check insert result?

$dml = "insert into table ..."; mysql_query($dml,$con); The above insert something into a table.then you can check if it succeeded by either if('' == mysql_error($con))... or if($id = mysql_insert_id($con))... What's your choice and…
user198729
  • 61,774
  • 108
  • 250
  • 348
1
vote
2 answers

Getting the wrong id using mysqli_insert_id

I am wanting to have the id returned after data is inserted into the database. There is a strong chance that multiple people will submit their forms at the same time. I don't want the wrong ID showing up in the results, because this ID will also…
horsey_kim
  • 137
  • 1
  • 7
1
vote
1 answer

Multiple mysql_insert_id

I have 3 table with structure like this, employee > id (PK), name family > family_id (PK), id (employee PK) father > father_id (PK), family_id (family PK), father_name I know I can get the last inserted id using mysql_insert_id() or…
Xtrader
  • 141
  • 3
  • 10
1
vote
1 answer

PHP - mysql_insert_id() and race conditions?

I think I've got a race condition within a bit of PHP code whereby mysql_insert_id() is returning 0 - but I can't work out why. $insertsess=mysql_query("insert into cior_sessions values…
GarySmith
  • 11
  • 1
1
vote
5 answers

mysql_insert_id() not returning a value -

I need to retrieve the auto increment field from my database table. I tried the following but $id is always just empty. The insert works too. My table is as follows: idint(9) NOT NULL auto_increment, and id is set as primary What am I doing wrong? …
I wrestled a bear once.
  • 22,983
  • 19
  • 69
  • 116
1
vote
6 answers

Why SQL INSERT query takes the entered values as column names

I have a problem with the SQL INSERT QUERY. Whenever I execute the INSERT QUERY in the below code, what happens, is the query understands the values to be entered as the column names. My code is : try { Class.forName("com.mysql.jdbc.Driver"); …
Roshan George
  • 187
  • 2
  • 2
  • 13
1
vote
1 answer

Running An Insert Query Grabbing The Id And Updating Another Table With Id

I need to insert a new row in to a table, then grab the ID of that row and update another table. This is what I have: $leadSQL="INSERT INTO $leadsTable (leadName, leadStatus, leadDescription, leadOpportunity, leadSource, leadSourceDescription, id,…
1 2
3
8 9