Search
 
SCRIPT & CODE EXAMPLE
 

PHP

get last inserted id in php

Example (MySQLi Procedural)
$last_id = mysqli_insert_id($conn);
Comment

mysql get the last id php

// Insert query 
$query = "insert into users(username,fname,lname) values('sonarika','Sonarika','Bhadoria')"; 

mysqli_query($con,$query); 

// Get last insert id 
$lastid = mysqli_insert_id($con); 
Comment

PHP MySQL Get Last Inserted ID

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', 'john@example.com')";

if ($conn->query($sql) === TRUE) {
  $last_id = $conn->insert_id;
  echo "New record created successfully. Last inserted ID is: " . $last_id;
} else {
  echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>
Comment

PREVIOUS NEXT
Code Example
Php :: php echo 
Php :: add script tag to wordpress Head 
Php :: how refresh object in database in laravel 
Php :: random string in laravel 
Php :: To store data in the session Laravel 
Php :: Could not find package laravel/ with stability stable. 
Php :: centos update php 7 to php 8 
Php :: php array_values 
Php :: laravel get first record 
Php :: php file for image load 
Php :: image uploading and validation php 
Php :: php mysqli connect err0r 
Php :: add request data in laravel request 
Php :: laravel sort by numbers 
Php :: wordpress get post by id 
Php :: Carbon Add Days To Date In Laravel 
Php :: server cmd php 
Php :: symfony password generator command line 
Php :: get taxonomies for custom post type 
Php :: php exercises 
Php :: php trim string if longer than 
Php :: php curl example 
Php :: laravel group routes 
Php :: laravel old value not working in textarea 
Php :: laravel tinker generate password 
Php :: get woocommerce order details 
Php :: simple localhost php 
Php :: php string contains 
Php :: mysqli last index php 
Php :: remove last all special character from string php 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =