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
0
votes
1 answer

How to use mysql_insert_id with a junction table

I have a form and three tables: customer, phone_number, and junction (to create a many-to-many relationship). I need the form to populate all three tables using the newly created auto-incremented ids from the customer and phone number tables to…
0
votes
2 answers

Error in mysql_insert_id() [MAIL TAG]

$headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: contact@email.com'; $to = $email; $subject = "Confirmation"; $message = "Hi, $username.…
0
votes
2 answers

php mysql_id() not getting last insert

Im getting a NULL return for the last insert id, I would appreciate if someone could check my code. I have placed an id number in place of the $result query and it returns the json echo. My hunch is that it has something to do with the placement of…
Adam
  • 297
  • 6
  • 20
0
votes
3 answers

Can't get mysql_insert_id() to work

I tried this: $cid = mysql_insert_id($this->result); $this->result = "
" . sprintf(_('Successfully added user id %s to the database.'), $cid) . "
"; but I only get this error: Warning: mysql_insert_id():…
Dreni
  • 161
  • 1
  • 5
  • 18
0
votes
1 answer

Is it possible to use mysql_insert_id() with a while loop?

while ($row = mysql_fetch_array($eventchoices)) { echo $row['res_name']. " and " .$row['event_name']; echo "
"; } Would like to get the last inserted row to be shown, this currently gets everything in the array, I tried to use…
zadubz
  • 1,281
  • 2
  • 21
  • 36
0
votes
1 answer

Getting the last record id through procedure

I am new learner and trying to get the last inserted id of a record. But here it's giving me the following error: Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use…
Dan
  • 73
  • 3
  • 8
0
votes
2 answers

Blank spaces in mysql_insert_id(); return

im getting blank spaces before my id? when it comes back i get this? &id=%20%20%20%20%20%20%20%20%20%20%20%201005 its supposed to just do this &id=1005 Could it be my jquery data code? success: function(data) { …
jonnypixel
  • 327
  • 5
  • 27
-1
votes
1 answer

if the booking id is varriable character, how to return last inserted id in codegniter

Blockquote how to return last inserted id , if the booking id is variable character in codeigniter** strong text **
sels
  • 1
  • 2
-1
votes
1 answer

Insert value from select within the same table

table:message [id,username,userid,message,type,timediff,timestamp] I have a table called message. When a message is started a new row is created, with a timestamp and timediff of null. When the message is ended I would like to insert that into a row…
-1
votes
1 answer

Get ID of first statement and post it in the second

I have a script that creates an user in the database: if ($insert_stmt = $mysqli->prepare("INSERT INTO members (username, email, password, salt) VALUES (?, ?, ?, ?)")) { $insert_stmt->bind_param('ssss', $username, $email, $password,…
John
  • 904
  • 8
  • 22
  • 56
-1
votes
2 answers

2nd query fails to run

I'm new to programming and I have a problem with the following code. The 2nd query is not running. It should insert all the data in the first database to the other database. MySQLConn = New MySqlConnection MySQLConn.ConnectionString =…
Newbie
  • 39
  • 4
-1
votes
1 answer

php/mysqli mysqli_insert_id() getting current id and re-inserting to another table

I'm not really sure how to use this mysqli_insert_id() function but here's what I'm trying to do! forum_threads.sql has auto incr. if(isset($_POST['createThread'])) { $db->real_query("INSERT INTO forum_threads (cata_id) VALUES ('1')"); $id =…
Jayden
  • 3
  • 1
  • 4
-1
votes
4 answers

mysql_insert_id() failed to retrieve auto increment ID

$dml = "insert into ... "; mysql_query($dml,$con); $Id = isset($row) ? $row['id'] : mysql_insert_id($con); I saw the record is created,but just can't retrieve the Id. What's wrong? EDIT fixed,it's caused by $row.
omg
  • 136,412
  • 142
  • 288
  • 348
-2
votes
1 answer

Copy data from one table to another with mysqli

I have some records in the db if I customer delete a record, I use that record id to copy the data from the that table and insert it into an archive table $sqlarch = "INSERT customers_archive SELECT * FROM customers_record WHERE UCI = '8233379' "
Lampstand
  • 1
  • 2
-2
votes
1 answer

Value of insert_id keeps returning 0

I'm trying to create a register form where I wish to let the user know the value of his ID. I'm able to successfully register the user but the insert_id keeps returning 0 even though there's multiple rows in the database. Database public function…
Cedric Woo
  • 39
  • 6
1 2 3
8
9