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 8814695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:11:37+00:00 2026-06-14T04:11:37+00:00

I will first show you the code, it’s easier to discuss this way. $message

  • 0

I will first show you the code, it’s easier to discuss this way.

 $message = $_GET['r'];
    $message = str_replace("%20", " ", $message);
    echo $message;

    mysql_query("INSERT INTO `uniform` (`note`,`cadetID) 
    VALUES ('$message','$cadet')");

    $query = mysql_query("SELECT `uniformID` FROM `cadets` WHERE id = '$cadet'");
    while ($row = mysql_fetch_array($query)) {
      $uniformA = $row['uniformID'];
    }

    if($uniformA == "0"){
      mysql_query("UPDATE `cadets` SET `uniformID` = '" .  ."'
      WHERE id = '$cadet'");
    }

Don’t worry about sanatisation for now.

I got to the line:

mysql_query("UPDATE `cadets` SET `uniformID` = '" .  ."' WHERE id = '$cadet'");

and realised I need the ID of the sql insert

mysql_query("INSERT INTO `uniform` (`note`,`cadetID) VALUES ('$message','$cadet')");

Is there an efficient way of getting the newly incremented ID from the database? Table structure as follows:

cadet(id[primary key, auto increment],...,uniformID)

uniform(id[prim key, auto inc], note, cadetID)

Data:

Cadet: 1,...,[1,2,3] <- all in the [] are in cadetID, array delimited by ‘,’

Uniform: 1, need a new blahh blahh, 1

Uniform: 2, new shoes needed, 1

And so forth.

So, in E-R speak, one cadet can have many uniform ID’s.

TL;DR I need to store the new ID in the database (auto incremented by SQL db) on a insert into

  • 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-14T04:11:38+00:00Added an answer on June 14, 2026 at 4:11 am

    I would suggest you change that to PDO and access it simply as this:

    $query = "INSERT INTO `uniform` ( `note`, `cadetID` ) VALUES ( ?, ? )";
    $params = array( $message, $cadet );
    
    $stmt = $db->prepare( $query );
    $stmt->execute( $params );
    
    $last_id = $db->lastInsertId();
    

    Here is nice tutorial and how to do that: http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers

    But in your case, you can use a query like this ( although it is not as safe ):

    SELECT LAST_INSERT_ID();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I will first illustrate my issue with some code: class ExampleClass { private Vector2
I know one awkward solution for this taks will be : first use ct
This will be my first iOS app with any bit of complexity. I'd like
I'm fairly new to writing test cases and this will be my first major
My problem is quite infuriating, actually. I'll show you the code first. /* **
First let me show some code. class User has_and_belongs_to_many :roles named_scope :employees, { :conditions
I have a client/server program and applet. I will show the code below. Can
First I'll show the code. class XLineEdit(QtGui.QLineEdit): '''QLineEdit with clear button, which appears when
I have the following code that is working (clicking on the link will show
Let me show the code first. WCF servicecontract function: public List<VenueData> GetVenues() { List<VenueData>

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.