I am expanding on an example I found that is intended to import Excel XML data into a database table. The database has been created, as has the table. I can see them via phpAdmin. And the XML file seems fine also.
While I’ve changed some things up in the example to reflect my situation I believe I’ve been careful not to mess anything up, but nothing happens when I run it. No errors. No nothing.
One line of code in particular (in Block 2) isn’t making complete sense yet, and that line is “if ( $_FILES[‘file’][‘tmp_name’] )”, and another line with the same “$_Files” reference. I’ve read up on that superglobal but this particular use of it is still unclear. I believe I know what “[‘file]’” refers to, but can someone explain to me what “[‘tmp_name]’” refers to?
If it isn’t obvious, code block 1 initiates code block 2. Take it easy on me please. I’m new to PHP. And I apologize for the many lines. Just figured I’d leave it all there.
Does anyone see any glaring errors?
Thanks!
Block 1
[php]
Choose file: |
Block 2 import_facilities.php
[php]<?php
$data = array();
$con=mysqli_connect(“localhost”,“root”,“password”,“facilities_db”);
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
function add_facility( $Facility_ID, $District, $PO_Name, $Unit_Name, $Street, $County, $City, $State, $ZIP_3, $ZIP_Code, $Ownership, $Maint_Resp, $Occupy_Date, $Int_SF, $Site_SF, $Annual_Rent )
{
global $data, $db;
$sth = $db->prepare( “INSERT INTO Facilities VALUES( 0, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)” );
$db->execute( $sth, array( $Facility_ID, $District, $PO_Name, $Unit_Name, $Street, $County, $City, $State, $ZIP_3, $ZIP_Code, $Ownership, $Maint_Resp, $Occupy_Date, $Int_SF, $Site_SF, $Annual_Rent ) );
$data []= array(
‘Facility_ID’ => $Facility_ID,
‘District’ => $District,
‘PO_Name’ => $PO_Name,
‘Unit_Name’ => $Unit_Name,
‘Street’ => $Street,
‘County’ => $County,
‘City’ => $City,
‘State’ => $State,
‘ZIP_3’ => $ZIP_3,
‘ZIP_Code’ => $ZIP_Code,
‘Ownership’ => $Ownership,
‘Maint_Resp’ => $Maint_Resp,
‘Occupy_Date’ => $Occupy_Date,
‘Int_SF’ => $Int_SF,
‘Site_SF’ => $Site_SF,
‘Annual_Rent’ => $Annual_Rent
);
}
if ( $_FILES[‘file’][‘tmp_name’] )
{
$dom = DOMDocument::load( $_FILES[‘file’][‘tmp_name’] );
$rows = $dom->getElementsByTagName( ‘Row’ );
$first_row = true;
foreach ($rows as $row)
{
if ( !$first_row )
{
$Facility_ID = “”;
$District = “”;
$PO_Name = “”;
$Unit_Name = “”;
$Street = “”;
$County = “”;
$City = “”;
$State = “”;
$ZIP_3 = “”;
$ZIP_Code = “”;
$Ownership = “”;
$Maint_Resp = “”;
$Occupy_Date = “”;
$Int_SF = “”;
$Site_SF = “”;
$Annual_Rent = “”;
$index = 1;
$cells = $row->getElementsByTagName( 'Cell' );
foreach( $cells as $cell )
{
$ind = $cell->getAttribute( 'Index' );
if ( $ind != null ) $index = $ind;
if ( $index == 1 ) $Facility_ID = $cell->nodeValue;
if ( $index == 2 ) $District = $cell->nodeValue;
if ( $index == 3 ) $PO_Name = $cell->nodeValue;
if ( $index == 4 ) $Unit_Name = $cell->nodeValue;
if ( $index == 5 ) $Street = $cell->nodeValue;
if ( $index == 6 ) $County = $cell->nodeValue;
if ( $index == 7 ) $City = $cell->nodeValue;
if ( $index == 8 ) $State = $cell->nodeValue;
if ( $index == 9 ) $ZIP_3 = $cell->nodeValue;
if ( $index == 10 ) $ZIP_Code = $cell->nodeValue;
if ( $index == 11 ) $Ownership = $cell->nodeValue;
if ( $index == 12 ) $Maint_Resp = $cell->nodeValue;
if ( $index == 13 ) $Occupy_Date = $cell->nodeValue;
if ( $index == 14 ) $Int_SF = $cell->nodeValue;
if ( $index == 15 ) $Site_SF = $cell->nodeValue;
if ( $index == 16 ) $Annual_Rent = $cell->nodeValue;
$index += 1;
}
add_facility( $Facility_ID, $District, $PO_Name, $Unit_Name, $Street, $County, $City, $State, $ZIP_3, $ZIP_Code, $Ownership, $Maint_Resp, $Occupy_Date, $Int_SF, $Site_SF, $Annual_Rent );
}
$first_row = false;
}
}
?>
Facility_ID | District | PO_Name | Unit_Name | Street | County | City | State | ZIP_3 | ZIP_Code | Ownership | Maint_Resp | Occupy_Date | Int_SF | Site_SF | Annual_Rent |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
<?php echo( $row['Facility_ID'] ); ?> | <<?php echo( $row['District'] ); ?> | <<?php echo( $row['PO_Name'] ); ?> | <<?php echo( $row['Unit_Name'] ); ?> | <<?php echo( $row['Street'] ); ?> | <<?php echo( $row['County'] ); ?> | <<?php echo( $row['City'] ); ?> | <<?php echo( $row['State'] ); ?> | <<?php echo( $row['ZIP_3'] ); ?> | <<?php echo( $row['ZIP_Code'] ); ?> | <<?php echo( $row['Ownership'] ); ?> | <<?php echo( $row['Maint_Resp'] ); ?> | <<?php echo( $row['Occupy_Date'] ); ?> | <<?php echo( $row['Int_SF'] ); ?> | <<?php echo( $row['Site_SF'] ); ?> | <<?php echo( $row['Annual_Rent'] ); ?> | <