Basically I think I have most of the code written properly with the exception of something. This script executes fine but it only inputs the customer information and nothing else.
I think it is something to do with the switching of databases in the middle, but I am unsure.
Any help would be appreciated.
Here is the main section of the code (sorry for the disorganization, it is a work in progress).
<?php
$EmployeeID=$_SESSION['eid'];
if(isset($_POST['submit'])){
$filename=$_POST['filename'];
$handle = fopen("$filename", "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE){
$connection = new mysqli($h['DCST'],$u['DCST'],$p['DCST'],$d['DCST']);
$connection->select_db($d['DCST']);
$importCust="INSERT into tblCustomers(CustomerID, CustName, CustNotes, AddrAttn, AddrLine1, AddrLine2, AddrCity, AddrStateProv, AddrPostalCode, Country, PhoneNumber1, PhoneNumber2, EmailAddress1, EmailAddress2, LastModifiedBy, LastModifiedTS) values(NULL, '$data[2]', NULL, NULL, '$data[5]', '$data[6]', '$data[7]', '$data[8]', '$data[9]', '$data[10]', '$data[3]', NULL, '$data[4]', NULL, NULL, NULL )";
$connection->query($importCust);
$IMCustomerID="SELECT CustomerID FROM tblCustomers WHERE CustName='$data[2]'";
$connection->query($IMCustomerID);
$connection->close();
$connection1 = new mysqli($h['DOST'],$u['DOST'],$p['DOST'],$d['DOST']);
$connection1->select_db($d['DOST']);
$importOrder="INSERT into tblOrders(OrderID, CustomerID, EmployeeID, ShipperID, ShipmentMethodID, OrderDate, ShipToName, ShipToAttn, ShipToAddrLine1, ShipToAddrLine2, ShipToCity, ShipToStateProvince, ShipToPostalCode, ShipToCountry, ShipToPhoneNumber, ShipNotes, ShippingDiscount, OSPIF, OSSHC, OSFBL, OSCLSD, OSCANCEL, PIFDate, SHCDate, FBLDate, CLSDDate, CANCELDate, LastModifiedBy, LastModifiedTS) values(NULL, '$IMCustomerID', '$EmployeeID', 'LEFT('$data[30]', 3)', NULL, 'curdate()', '$data[2]', NULL, '$data[5]', '$data[6]', '$data[7]', '$data[8]', '$data[9]', '$data[10]', '$data[3]', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )";
$connection1->query($importOrder);
$IMOrderID="SELECT OrderID FROM tblOrders WHERE CustomerID='$IMCustomerID' ";
$connection1->query($IMOrderID);
$IMListingID="SELECT ListingID, SubmissionID FROM tblListings WHERE AuctionNumber='$data[11]' ";
$connection1->query($IMListingID);
$importOrderListingDetail="INSERT into tblOrderListingDetails(OrderID, ListingID, WinningBid, FeedbackID, DateFeedbackLeft, LastModifiedBy, LastModifiedTS) values('$IMOrderID', '$IMListingID[0]', '$data[15]', NULL, NULL, NULL, NULL ";
$connection1->query($importOrderListingDetail);
$IMItemID="SELECT ItemID FROM tblSubmissionItemDetails WHERE SubmissionID='$IMListingID[1]' ";
$connection1->query($IMItemID);
$importOrderItemDetail="INSERT into tblOrderItemDetails(OrderID, ItemID, LastModifiedBy, LastModifiedTS) values('$IMOrderID', '$IMItemID', NULL, NULL ";
$connection1->query($importOrderItemDetail);
$query = "UPDATE tblListings set DateEnded=DATE_FORMAT('$data[22]', '%y %b %d') AND BilledShippingHandling='$data[16]' WHERE ListingID='$IMListingID[1]'";
$connection1->query($query);
$connection1->close();
}
fclose($handle);
echo "Import done";
}
else
{
print "<form action='csveb.php5' method='post'>";
print "Type file name to import:<br>";
print "<input type='text' name='filename' size='20'><br>";
print "<input type='submit' name='submit' value='submit'></form>";
}
?>