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

  • SEARCH
  • Home
  • 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 6197515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:50:05+00:00 2026-05-24T03:50:05+00:00

Here is an easy one, but can’t figure out why is not working. Need

  • 0

Here is an easy one, but can’t figure out why is not working. Need another set of eyes.
3 queries. 1 insert, 1 select, then 1 insert again. My select query is supposed to grab a value from the data recently inserted, and then store that value in a variable, then run the second insert for another table. Well, everything works, except the select. I even tryied to add a mysql_query(“COMMIT”,$conn) and still nothing.
Any help is very appreciated.
Thanks!!!

$customerQ = "INSERT INTO
customerData(fname, mname, lname, email, homePhone, cellphone, address, 
city, county, state, zip, gascompany, eleccompany, addedBy)
VALUES('$fname', '$mname', '$lname', '$emailCustomer', '$hphone', '$cellphone',
  '$address', '$city', '$county', '$state', '$zip', '$gas', '$electric', 
  '$userName'
) ";             
//General WO# calculation
$calcWO = "SELECT 
              auditRequest.workOrderNum
            FROM
              auditRequest
            ORDER BY
               auditRequest.workOrderNum DESC
            LIMIT 1
        ";  

//General Customer number calculation. For the Work Order Insert
$calc = "SELECT
              customerData.custnumber
           FROM
              customerData
           WHERE
              fname = '$fname' and
              mname = '$mname' and
              lname = '$lname'
           ORDER BY
           customerData.custnumber DESC
           LIMIT 1
     "; 

    //Customer Information Insert (from Insert Query)
    $resultCustQ = mysql_query($customerQ, $connection);
    mysql_query("COMMIT", $connection); //make sure to commit to be able to query new records
    // Test the query
    if(!$resultCustQ) die ("error 1". mysql_error());

    //Customer Information Insert (from Insert Query)
    $resultCustQ = mysql_query($customerQ, $connection);
    mysql_query("COMMIT", $connection); //make sure to commit to be able to query new records
    // Test the query
    if(!$resultCustQ) die ("error 1". mysql_error());

    //Calculate new customer number
    $calc_result = mysql_query($calc, $connection);
    // Test the query
    if(!$calc_result) die ("error 1". mysql_error());
    $row=mysql_fetch_array($calc_result);
    $custnum = $row['custnumber']; // This is the new Customer.

    //Work Order Information (run SQL Insert)
    $resultWOQ = mysql_query($workOrderQ, $connection);
// Test the query
    if(!$resultWOQ) die ("error 1". mysql_error());
  • 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-05-24T03:50:06+00:00Added an answer on May 24, 2026 at 3:50 am

    I would avoid the crutch of INSERT followed by SELECT to find the inserted record altogether and use MySQL’s ability to return the ID of the most recently inserted row (provided your table as an AUTO INCREMENT primary key) via PHP’s mysql_insert_id, also available through PDO via lastInsertId.

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

Sidebar

Related Questions

Afternoon all. Here's an easy one for you that I can't figure out. I
This is probably an easy one, but I can't figure it out. argh... C#
This is most likely not an easy one but here is the situation: I
This is a fairly easy one, but I cant seem to figure it out.
Such an easy question but I can't figure it out... function pageLoad() { runDatepickers();
This seems like it should be an easy one but I can't figure it
I know this should be fairly easy but I can't quite figure it out
Here's an easy one straight from the text book I can't seem to find.
I can't find the answer in my book and it's an easy one but
A really easy one, but I need to get this right, and cannot afford

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.