Insert the record number of one mySQL table into a second mySQL table.

I'm trying to write to two mySQL tables at the same time.  I have been able to write a test field, but I am trying to write a var to the table.  I want to write the record number ($theRN)  of the first table into the second table.  This is my code:

===================================================
if ((isset($_POST["InsertProducts"])) && ($_POST["InsertProducts"] == "form1")) {
  $insertSQL2 = sprintf("INSERT INTO Products (Name, Display_Name, Brief_Description, Part_no, Short_name, Change_Date, Base_Price, Bullet1, Bullet2, Bullet3, Bullet4, Model_No, Large_Image, Tax_Item, Handling_Fee, Weight, Ship_Using_Old, Postage_Is) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s,   %s, %s, %s, %s, %s, %s, %s, %s )",
                                      GetSQLValueString($_POST['name'], "text"),
                                 GetSQLValueString($_POST['title'], "text"),
                                 GetSQLValueString($_POST['description'], "text"),                                 
                                 GetSQLValueString($_POST['Product_no'], "text"),
                                 GetSQLValueString($_POST['Product_no'], "text"),                                 
                                          GetSQLValueString($_POST['today'], "date"),
                                 GetSQLValueString($_POST['SubTotal_pri'], "double"),         
                                  GetSQLValueString($_POST['title'], "text"),
                                 GetSQLValueString($_POST['project'], "text"),
                                          GetSQLValueString($_POST['HUsername'], "text"),                                                
                                          GetSQLValueString($_POST['quote_no'], "text"),
                                 GetSQLValueString($_POST['Product_no'], "text"),
                                 GetSQLValueString($_POST['imageH'], "text"),
                                 GetSQLValueString($_POST['tax_item'], "text"),
                                 GetSQLValueString($_POST['Crate_pri'], "double"),
                                          GetSQLValueString($_POST['ship_Wt'], "int"),
                                 GetSQLValueString($_POST['ship_using'], "int"),
                              //   GetSQLValueString($_POST['ship_optH'], "int"),  "Ship_Service" has been removed from the db
                                 GetSQLValueString($_POST['postage_is'], "int"));
                              //   GetSQLValueString($_POST['Shipping_pri'], "double"));   "Postage" has been removed from the db
                                    
  mysqli_select_db($database_squirrelcart, $squirrelcart);
  $Result2 = mysqli_query($squirrelcart, $insertSQL2) or die(mysqli_error());
 
      $theRN = mysqli_insert_id($squirrelcart);
      
//  Write Shipping data to Products_Ship_Setting  
  $insertSQL3 = sprintf("INSERT INTO Products_Ship_Settings (Products_rn, Postage_1 )VALUES (%theRN, %s )",
                              GetSQLValueString($_POST['Shipping_pri'], "double"));

  mysqli_select_db($database_squirrelcart, $squirrelcart);
  $Result3 = mysqli_query($squirrelcart, $insertSQL3) or die(mysqli_error());      

 
  header("Location: https://www.eshowerdoor.com/store.php?crn=0&rn=$theRN&action=show_detail");
}

======================================
I was successful in writing into the first table and just the "Shipping_pri" into the second table, but I crash when I added the "$theRN".  The record number is an integer in both tables.
jws2bayAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Terry WoodsIT GuruCommented:
Have you got the error code/message from when the query fails? If you're not sure how to get it, let us know and we can explain.
0
Chris StanyonWebDevCommented:
The syntax of your second sprintf function is wrong. You need 2 placeholders and 2 parameters. It should be this:

$theRN = mysqli_insert_id($squirrelcart);
      
$insertSQL3 = sprintf("INSERT INTO Products_Ship_Settings (Products_rn, Postage_1) VALUES (%s, %s)", $theRN, GetSQLValueString($_POST['Shipping_pri'], "double"));

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jws2bayAuthor Commented:
Hi Chris,  Your answer pointed in the right direction.  The only change needed was in the syntax of the var.   This worked for me.

$theRN = mysqli_insert_id($squirrelcart);
     
$insertSQL3 = sprintf("INSERT INTO Products_Ship_Settings (Products_rn, Postage_1) VALUES (%s, %s)",
GetSQLValueString($theRN, "int"),
GetSQLValueString($_POST['Shipping_pri'], "double"));

==================================
Terry:    I was getting a white screen.  How do you pull the error message?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.