I have a form that I'm trying to use to Insert to two tables, using the Auto-incremented CustomerID from the first table and inserting it into the second table. My code inserts correctly into the first table but doesn't insert anything into the second table. My code is below. What do I have wrong? Thanks.
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
$insertSQL = sprintf("INSERT INTO Customers2 (CustomerID, CustomerFirstName, CustomerLastName, CustomerCompany, CustomerPhone, CustomerAddress, CustomerCity, CustomerState, CustomerZip, CustomerEmail, CustomerPassword, CustomerAccountType) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['CustomerID'], "int"),
GetSQLValueString($_POST['CustomerFirstName'], "text"),
GetSQLValueString($_POST['CustomerLastName'], "text"),
GetSQLValueString($_POST['CustomerCompany'], "text"),
GetSQLValueString($_POST['CustomerPhone'], "text"),
GetSQLValueString($_POST['CustomerAddress'], "text"),
GetSQLValueString($_POST['CustomerCity'], "text"),
GetSQLValueString($_POST['CustomerState'], "text"),
GetSQLValueString($_POST['CustomerZip'], "text"),
GetSQLValueString($_POST['CustomerEmail'], "text"),
GetSQLValueString($_POST['CustomerPassword'], "text"),
GetSQLValueString($_POST['CustomerAccountType'], "text")
);
mysql_select_db($database_conn, $conn);
$Result1 = mysql_query($insertSQL, $conn) or die(mysql_error());
}
// Insert into Accounts table
$CustomerID=mysql_insert_id();
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
$CustomerID=mysql_insert_id();
$StartBalance=$_POST['StartBalance'];
$insertAccountSQL = "INSERT INTO Accounts
CustomerID='$CustomerID',
StartBalance='$StartBalance'
" ;
mysql_select_db($database_conn, $conn);
$Result2 = mysql_query($insertAccountSQL, $conn) or die(mysql_error());
}