Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8339367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:52:03+00:00 2026-06-09T04:52:03+00:00

I don’t think I am doing this correctly and problem is that because I

  • 0

I don’t think I am doing this correctly and problem is that because I am using ajax to perform this code in the php script in the background, I can’t check for any errors I may have.

Does the variable $lastID actually retrieve the id from the “ImageId” field which was last inserted or is it not doing this at all? If it is not retrieving the last ID then what do I actually need to do in order to be able to retrieve the last ImageId id?

ImageId is an auto increment field:

Below is code:

$imagesql = "INSERT INTO Image (ImageFile) VALUES (?)";

if (!$insert = $mysqli->prepare($imagesql)) {
    // Handle errors with prepare operation here
}

//Dont pass data directly to bind_param store it in a variable
$insert->bind_param("s", $img);

//Assign the variable
$img = 'ImageFiles/' . $_FILES['fileImage']['name'];

$insert->execute();

//RETRIEVE IMAGEID FROM IMAGE TABLE

$lastID = $mysqli->insert_id;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:52:05+00:00Added an answer on June 9, 2026 at 4:52 am

    You should use

    $mysqli->insert_id;
    

    to get the last inserted id.
    Official PHP doc page is here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't think that I'm mad, I understand how php works! That being said. I
Don't think my virtualhost is working correctly. This is what I have inside of
Don't think this is a repost, difficult to search for the word between because
Don't be scared of the extensive code. The problem is general. I just provided
I don't know why, but this code worked for me a month ago... maybe
Don't know why this is happening, but after submitting a form via JS (using
Don't know if this is an eclipse specific problem but whenever I declare a
don't know if this is possible.. I'm using sqlite3 schema: CREATE TABLE docs (id
Don't ask me why but i can't use this method because I need to
Don't think there's much to say, here's my code for (int i = 0;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.