Questions tagged [insert-id]

47 questions
2
votes
1 answer

PHP MySQLi and MySQLi_STMT: Which insert_id to use?

Both the MySQLi and MySQLi_STMT classes have an $insert_id property. If I am connected to my database using a MySQLi object (say $db), and then I perform an INSERT with a MySQLi_STMT object (say $stmt), to get the id of the last INSERT, should I…
Carvell Fenton
  • 2,341
  • 6
  • 23
  • 30
1
vote
1 answer

MySQL PhpMyAdmin: Alter AUTO_INCREMENT and/or INSERT_ID

I have an invoices table which stores a single record for each invoice, with the id column (int AUTO_INCREMENT) being the primary key, but also the invoice reference number. Now, unfortunately I've had to manual migrate some invoices generated on an…
Dave White
  • 321
  • 1
  • 3
  • 13
1
vote
1 answer

Last insert value always returns zero

Trying to get the id of the last insert using a prepared statement. mysqli_insert_id always returns zero. $sql = "INSERT INTO classes (id_course, id_organization, start_date, end_date, status, id_creator, assign_interval) VALUES (?, ?, ?, ?, ?, ?,…
MarkO
  • 15
  • 2
1
vote
1 answer

Mysqli insert id: $mysqli->insert_id; or $stmt->insert_id?

which one is the correct code in a prepared statement? $ID_user=$mysqli->insert_id; or $ID_user=$stmt->insert_id; ? $stmt = $mysqli->prepare("INSERT INTO users (first_name, last_name) VALUES (? …
ely81
  • 21
  • 3
1
vote
1 answer

insert_id in Kohana 3

I'm using Kohana 3 framework with Mysql stored procedures. How can I get id of the last inserted record? Here's the code: class Model_MyModel extends Kohana_Model { public function insertNew($param1, $param2) { $result =…
skog
  • 31
  • 1
  • 4
1
vote
2 answers

PHP, mysql, primary key remains unchanged for two records

I've got following code, as seen, I have two INSERT statements, which insert two records - one with current date and the second one -1 day. The problem seems to be with a mysql_insert_id. I'm getting following error: Duplicate entry '28' for key…
1
vote
1 answer

Return the id of the last MySQL insert in PHP

I'm trying to grab the id of the last inserted auto-increment row and cannot successfully grab it. error_reporting(E_ALL); ini_set('display_errors', 1); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); $title =…
1
vote
6 answers

Private Messaging System With Threading/Replies

I'm currently working on creating a private messaging system, (PHP/MySQL) in which users can send message to multiple recipients at one time, and those users can then decide to reply. Here's what I'm currently working with: tbl_pm…
Dodinas
  • 6,705
  • 22
  • 76
  • 108
0
votes
1 answer

Request Body in BigQuery

Good Day, I am testing a post method in another system using BigQuery as its data source. I am currently testing the call method on BigQuery's live data to see if the API request gets a response. What I want to know is: is the insertId meant to be…
user17311472
0
votes
0 answers

PHP/MYSQLI insert_id for foreign key value - $id variable set but not working in INSERT query

Using the code below, I am auto-incrementing an ID value as a primary key in the constant_client table, which then needs to be used as a foreign key in the varying_client table. The first prepared statement works correctly, and the $id variable…
Carbs
  • 23
  • 5
0
votes
1 answer

insert_id mysqli

I'm trying to return the inserted id from a mysql INSERT query. Each time I run the function I get 0 as the result. Can someone please explain at what point I can retrieve the value because although the script below executes I cannot retireve the…
paynod
  • 19
  • 1
  • 7
0
votes
1 answer

CodeIgniter, Ajax... How to use insert_id()

Excuse my English, I hope you can understand my question... In my program, when you submit a new record to the database (MySQL) using a modal+form, it is drawn in a data table without refreshing or recharging the actual page, it's appended…
Nira
  • 197
  • 1
  • 1
  • 12
0
votes
1 answer

How to get my ID on codeigniter?

Struckuter So i want when i input blablabla on tproject, automatic id from id project to tproject_pic but when i using blabla, no record on tproject_pic, whts wrong? Controller $data = array( 'id' => '', 'division' => $division, 'client'=>…
0
votes
1 answer

Codeigniter and Oracle get the last_id of insert query

I have model like this: function data_input($data, $file_upload) { $this->db->set('ID_KEY', "LASTID_SEQ.NEXTVAL", FALSE); //false escape $this->db->insert('FIRST_TABLE', $data); $this->db->set('ID_KEY', "LASTID_SEQ.NEXTVAL -1", FALSE);…
0
votes
0 answers

Getting Identity-Generated primary key from JPA

I'm using Netbeans 8.1, Java EE 7, and MS SQL Server. The application does transactions that contain individual items stored in a separate table. I need the primary key txId to create the individual records that are linked with a Foreign Key. Here…
davef
  • 77
  • 1
  • 6