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 :: how to calculate days difference between two dates in php 
Php :: how to redirect a particular user role to a page after login laravel 
Php :: get random data laravel 
Php :: how to pass variable in inside function into where in laravel 
Php :: how to get the average in sql in php 
Php :: nav active in laravel 
Php :: get order details by id woocommerce 
Php :: laravel date default now 
Php :: method put laravel 
Php :: wordpress get field 
Php :: get url parameters in laravel blade 
Php :: update eloquent with increment laravel 
Php :: php remove prefix from string 
Php :: php check version ubuntu 
Php :: acf gallery 
Php :: change date format php 
Php :: php shell script 
Php :: get the category wp 
Php :: delete method laravel 
Php :: php session time out default 
Php :: php import python script 
Php :: laravel migrate seed 
Php :: wordpress theme directory uri 
Php :: random word using a wordlist php 
Php :: strtotime format 
Php :: make select element readonly 
Php :: json whereIn laravel 
Php :: convert multi-dimensional array into a single array in laravel 
Php :: https redirect in htacess for php laravel 
Php :: laravel http retry 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =