jponte Posted February 22, 2010 Share Posted February 22, 2010 Hi PHP Freaks, I'am able to pick the last record created but I cannot pass it to the second query. What I'm I doing wrong?? Going crazy if(!isset($ContactIDVal)){ $Query2 = "INSERT into rma_contact (Cont_Attention, Cont_Phone, Cont_Email, Cont_Address, Cont_Add_Address, Cont_City, Cont_Prov, Cont_Postal, Cont_Add_Info) values ('$ShipAttention', '$ShipPhone', '$ShipEmail', '$ShipStreet', '$ShipAddinfo', '$ShipCity', '$ShipProv', '$ShipPCode', '$ShipAddNotes')"; $Query = "INSERT into rma_devices values ('$RMANumber', '$CustomerID', '$RMADate', '$DevicePhone', '$DeviceType', '$DeviceModel', '$DeviceIMEI', '$DeviceColor', '$DescDefect', '$ResetDevice', '$SoftwareReload', '$WipeDevice', '$TroubOther', '$TroubNotes', '$Gen_Contact_ID')"; //does not display the Gen_Contact_ID if (mysql_db_query ($DBName, $Query2, $Link)) { //Get the generated ID for Contact_ID $Gen_Contact_ID = mysql_insert_id(); //Print the Insert id printf("Last inserted record has id %d\n", mysql_insert_id()); echo $Gen_Contact_ID; //PRINTS OK print ("<br>The Query 2 has been saved to the ESC database<br>\n"); } else {print ("There was a problem saving the RMA form to the database<br>Please contact ESC at 1-877-939-3282\n"); echo "<BR><BR>Error message = ".mysql_error(); } if (mysql_db_query ($DBName, $Query, $Link)) { echo $Gen_Contact_ID; //PRINTS OK print ("<br> The Query 1 has been saved to the ESC database<br>\n"); } else {print ("There was a problem saving the RMA form to the database<br>Please contact ESC at 1-877-939-3282\n"); echo "<BR><BR>Error message = ".mysql_error(); } } else{ $Gen_Contact_ID = $contactinfo ['Contact_ID']; print ("<BR>Break: $Gen_Contact_Info<BR>\n"); $Query3 = "INSERT into rma_devices values ('$RMANumber', '$CustomerID', '$RMADate', '$DevicePhone', '$DeviceType', '$DeviceModel', '$DeviceIMEI', '$DeviceColor', '$DescDefect', '$ResetDevice', '$SoftwareReload', '$WipeDevice', '$TroubOther', '$TroubNotes', '$Gen_Contact_ID')"; if (mysql_db_query ($DBName, $Query3, $Link)) { echo $Gen_Contact_ID; print ("<br> The Query 1 has been saved to the ESC database<br>\n"); } else {print ("There was a problem saving the RMA form to the database<br>Please contact ESC at 1-877-939-3282\n"); echo "<BR><BR>Error message = ".mysql_error(); } } if (!$link = mysql_connect('localhost', 'root', 'escrma')) { echo 'Could not connect to mysql'; exit; } if (!mysql_select_db('rma_portal', $link)) { echo 'Could not select database'; exit; } print ("<br>The Query2 is:<BR>$Query2<P>\n"); print ("<br>The Query1 is:<BR>$Query<P>\n"); print ("<br>The Query3 is:<BR>$Query3<P>\n"); mysql_close ($Link); Quote Link to comment https://forums.phpfreaks.com/topic/192893-mysql_insert_id-not-passing-the-number/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 22, 2010 Share Posted February 22, 2010 You do understand that code is executed from top to bottom and that variables don't have values in them until the code that assigns a value has been executed. You are trying to use the variable $Gen_Contact_ID in your code that is building the string in $Query before $Gen_Contact_ID has been assigned a value. Are you developing and debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON in your php.ini so that php would report and display all the errors it detects? You would be getting a undefined error concerning $Gen_Contact_ID when you try to use it before it has been assigned a value. Quote Link to comment https://forums.phpfreaks.com/topic/192893-mysql_insert_id-not-passing-the-number/#findComment-1015940 Share on other sites More sharing options...
jponte Posted February 22, 2010 Author Share Posted February 22, 2010 Hi, When should I run $query then so it will use it .....I just can see it Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/192893-mysql_insert_id-not-passing-the-number/#findComment-1015942 Share on other sites More sharing options...
jponte Posted February 22, 2010 Author Share Posted February 22, 2010 Got it....Thanks Quote Link to comment https://forums.phpfreaks.com/topic/192893-mysql_insert_id-not-passing-the-number/#findComment-1015943 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.