Why am I getting this "non-object" error?

Head out to http://hihatwebdesign.com/test/volte.htm and you'll see the output of the code I have below.

I've got all sorts of stuff that I want to do as far as taking the contents of the referenced html file and inserting it into a database, but I can't get past a fatal error that you'll see when you out to the page I've got referenced above.

It starts at line 33 where it says you can't assign a property to a non-object and then it becomes lethal when the same "non-object" is accessed in the getElementsbyTagName.

When I output my html file, I get the data I'm expecting. But for some reason, my code isn't "seeing it" and I don't know why.

Why am I getting this "non-object" message and what do I need to do to fix it?

Here's my code in full, although the problem begins at line 33, so the rest, for right now, isn't relevant until I get this first mess cleaned up.

Thanks!

<?php
date_default_timezone_set('America/Chicago');
//I was getting some warnings on this page that seemed more about format then they did content. In an effort to keep it clean, yet accurate, I just activated "error_reporting(0)"
error_reporting(E_ALL);
ini_set('max_execution_time', 1200);
libxml_use_internal_errors(false);
require 'common.php';
echo 'STARTING PROCC VOLTE VOLTE 7 DAY TBL ' . date('h:i:s') . "<br>";


$html = file_get_contents('../uploads/volte_7day.html');
//var_dump($html);
$delete_query="delete from tbl_volte7";
//echo $delete_query;
$query_1 = mysqli_query($con, $delete_query);
if(!$query_1)
{
	echo "your delete query didn't work";
}

    /*** a new dom object ***/ 
    $file = new domDocument; 
	
	/*** load the html into the object ***/ 
	//introduced "@file" to suppress invalid HTML markup warnings
	$dom=@$file->loadHTML($html); 
	
	if(!$dom)
	{
		echo "You don't have data";
	}
	    /*** discard white space ***/ 
    $dom->preserveWhiteSpace = false; 

/*** the table by its tag name ***/ 
    $tables = $dom->getElementsByTagName('table'); 

    /*** get all rows from the table ***/ 
    $rows = $tables->item(0)->getElementsByTagName('tr'); 

    /*** loop over the table rows ***/ 
    foreach ($rows as $row) { 
        /*** get each column by tag name ***/ 
$cols = $row->getElementsByTagName('td'); 

$enddate = $cols->item(0)->nodeValue;
$num_days = $cols->item(1)->nodeValue;
$area = $cols->item(2)->nodeValue;
$mmepool = $cols->item(3)->nodeValue;
$region = $cols->item(4)->nodeValue;
$vendor = $cols->item(5)->nodeValue;
$volte_ia_pcnt = $cols->item(6)->nodeValue;
$volte_lc_pcnt = $cols->item(7)->nodeValue;
$sip_mou = $cols->item(8)->nodeValue;
$volte_qci1_setup_failure_pcnt = $cols->item(9)->nodeValue;
$volte_qci1_setup_failures = $cols->item(10)->nodeValue;
$volte_qci1_setup_attempts = $cols->item(11)->nodeValue;
$qci5_setup_failure_pcnt = $cols->item(12)->nodeValue;
$qci5_setup_failures = $cols->item(13)->nodeValue;
$qci5_setup_attempts = $cols->item(14)->nodeValue;
$seer_pcnt = $cols->item(15)->nodeValue;
$seer_sip_ntwk_eff_calls = $cols->item(16)->nodeValue;
$seer_sip_call_attempts = $cols->item(17)->nodeValue;
$rrc_setup_failure_pcnt = $cols->item(18)->nodeValue;
$rrc_setup_attempts = $cols->item(19)->nodeValue;
$rrc_setup_failures = $cols->item(20)->nodeValue;
$volte_qci1_drop_pcnt = $cols->item(21)->nodeValue;
$volte_qci1_drops = $cols->item(22)->nodeValue;
$volte_qci1_established_calls = $cols->item(23)->nodeValue;
$qci5_bearer_drop_pcnt = $cols->item(24)->nodeValue;
$qci5_bearer_drops = $cols->item(25)->nodeValue;
$qci5_bearer_estab_calls = $cols->item(26)->nodeValue;
$volte_avg_mos = $cols->item(27)->nodeValue;
$volte_mos_numerator = $cols->item(28)->nodeValue;
$volte_mos_denominator = $cols->item(19)->nodeValue;
$volte_pdcp_dl_volume_mb = $cols->item(30)->nodeValue;
$volte_dl_volume_pcnt = $cols->item(31)->nodeValue;
$lte_pdcp_dl_volume_mb = $cols->item(32)->nodeValue;
$x7x24_volte_pdcp_dl_volume_mb = $cols->item(33)->nodeValue;
$x7x24_volte_dl_volume_pcnt = $cols->item(34)->nodeValue;
$x7x24_lte_pdcp_dl_volume_mb = $cols->item(35)->nodeValue;
$volte_pdcp_ul_volume_mb = $cols->item(36)->nodeValue;
$volte_ul_volume_pcnt = $cols->item(37)->nodeValue;
$lte_pdcp_ul_volume_mb = $cols->item(38)->nodeValue;
$x7x24_days = $cols->item(39)->nodeValue;


$ran_ia_pcnt = $volte_qci1_setup_failure_pcnt + $qci5_setup_failure_pcnt + $rrc_setup_failure_pcnt ;
$seer_ia_pcnt = 100 - $seer_pcnt;


if ($region == 'Carolinas/Tennessee') {$region = 'CAR/TN';}
if ($region == 'Central Texas') {$region = 'CTX';}
if ($region == 'Florida') {$region = 'FL';}
if ($region == 'Georgia/Alabama') {$region = 'GA/AL';}
if ($region == 'Houston/Gulf Coast') {$region = 'HGC';}
if ($region == 'South Central') {$region = 'SCTL';}

if ($enddate <> '' ){
$q1 = "insert into tbl_volte7(enddate,latest_date,area,region,vendor,ran_ia_pcnt,seer_ia_pcnt,volte_lc_pcnt,sip_mou,volte_qci1_setup_failure_pcnt,volte_qci1_setup_failures,volte_qci1_setup_attempts,qci5_setup_failure_pcnt,qci5_setup_failures,qci5_setup_attempts,seer_pcnt,seer_sip_ntwk_eff_calls,seer_sip_call_attempts,rrc_setup_failure_pcnt,rrc_setup_attempts,rrc_setup_failures,volte_qci1_drop_pcnt,volte_qci1_drops,volte_qci1_established_calls) VALUES ('$enddate','$latest_date','$area','$region','$vendor','$ran_ia_pcnt','$seer_ia_pcnt','$volte_lc_pcnt','$sip_mou','$volte_qci1_setup_failure_pcnt','$volte_qci1_setup_failures','$volte_qci1_setup_attempts','$qci5_setup_failure_pcnt','$qci5_setup_failures','$qci5_setup_attempts','$seer_pcnt','$seer_sip_ntwk_eff_calls','$seer_sip_call_attempts','$rrc_setup_failure_pcnt','$rrc_setup_attempts','$rrc_setup_failures','$volte_qci1_drop_pcnt','$volte_qci1_drops','$volte_qci1_established_calls')";
echo $q1;
$insert = mysqli_query($con, $q1) ;
if(!$insert)
{
	echo "your insert query didn't happen";
}

}
} 


$q2 = "select avg(ran_ia_pcnt) as area_ran_ia_pcnt, avg(seer_ia_pcnt) as area_seer_ia_pcnt, (sum(volte_qci1_drops)/sum(volte_qci1_established_calls))*100 as area_volte_lc_pcnt, sum(sip_mou) as area_sip_mou  from tbl_volte7"; 
//echo $q2  . "<br>";
$r2 = mysql_query($q2) or die(mysql_error()); 
$row1 = mysql_fetch_assoc($r2);


$area_ran_ia_pcnt = round($row1['area_ran_ia_pcnt'],3);
$area_seer_ia_pcnt = round($row1['area_seer_ia_pcnt'],3);
$area_volte_lc_pcnt = round($row1['area_volte_lc_pcnt'] ,3);
$area_sip_mou = $row1['area_sip_mou'];

$q3 = "insert into tbl_volte7 set region = 'AREA', ran_ia_pcnt = '$area_ran_ia_pcnt', seer_ia_pcnt= '$area_seer_ia_pcnt', volte_lc_pcnt = '$area_volte_lc_pcnt', sip_mou = '$area_sip_mou' "; 
//echo $q2  . "<br>";
$insert_2=mysqli_query($con, $q3);
if(!$insert_2)
{
	echo "your averages didn't work";
}

mysql_close($con); 
 
echo 'COMPLETED PROCC VOLTE 7 DAY TBL ' . date('h:i:s') . "<br>";

 

?> 

Open in new window

Bruce GustPHP DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
$dom=@$file->loadHTML($html);
returns a boolean, and not an object

http://php.net/manual/en/domdocument.loadhtml.php
Return Values
Returns TRUE on success or FALSE on failure. If called statically, returns a DOMDocument or FALSE on failure. 

Open in new window


you have to continue to use $file and not $dom in the next lines
Bruce GustPHP DeveloperAuthor Commented:
Guy, that makes sense, but what would that look like?

If the first place where everything goes south is: $dom->preserveWhiteSpace and I've declared $dom as $dom=@$file->loadHTML, I'm thinking that at that point my "object" is $dom and you're saying that I've got keep using $file.

Not arguing, just trying to figure out how to correctly apply your suggestion.

How would the corrected lines look (specifically #33 [$dom->preserveWhiteSpace=false] and #36 [$table=$dom->getElementsByTagName]) look?
Guy Hengel [angelIII / a3]Billing EngineerCommented:
Again: $dom is just a boolean value.
Use $file->preservewhitespace and $table = $file->getelementsbytagname... and it should work
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

Bruce GustPHP DeveloperAuthor Commented:
Guy! We're making progress!

I was finally able to figure out what you meant by a "boolean" value. Just to make sure I'm tracking with you, "boolean" isn't data as much as it's a declaration as to whether or not something is or isn't, often expressed as either True or False.

That being the case, because of the way I had things set up, I was looking for data in a "True" and that's not going to fly.

Still not out of the woods, though...

Everything is swimming along until I actually start trying to retrieve data and I'm still stuck. Check it out:

 $file = new domDocument; 
	
	/*** load the html into the object ***/ 
	//introduced "@file" to suppress invalid HTML markup warnings
	$dom=@$file->loadHTML($html); 
	
	if(!$dom)
	{
		echo "You don't have data";
	}
	    /*** discard white space ***/ 
    $file->preserveWhiteSpace = false; 

/*** the table by its tag name ***/ 
    $tables = $file->getElementsByTagName('table'); 

    /*** get all rows from the table ***/ 
    $rows = $tables->item(0)->getElementsByTagName('tr'); 

    /*** loop over the table rows ***/ 
    foreach ($rows as $row) { 
        /*** get each column by tag name ***/ 
$cols = $row->getElementsByTagName('td'); 

$enddate = $cols->item(0)->nodeValue;

Open in new window


I've done a "if($tables) echo "we've got data"; } and confirmed some kind of digital presence with tables, rows and columns. But when I get to $enddate=$cols->item(0)->nodeValue, I get:

Trying to get property of non-object in /var/www/html/sasite/weekly_reports/procedures/procc_volte_7day.php on line 46

So, I'm still blowing it somewhere. Any ideas?
Guy Hengel [angelIII / a3]Billing EngineerCommented:
that means that either  $cols or  $cols->item(0) is not an object ....
Bruce GustPHP DeveloperAuthor Commented:
When I do a var_dump($cols), I get this:

" object(DOMNodeList)#8 (1) { ["length"]=> int(0) }

This killing me, Guy! When I do if($cols){echo "you've got data";}, I get "you've got data." But then after doing a var_dump, it doesn't look like I've got squat and I don't even know where to start to figure out what I have, if I've got anything.

What's the next move?
Ray PaseurCommented:
var_dump($cols) is giving you some data -- an object with one property named "length."  That's enough for PHP to account for a truthy type juggle.  PHP is loosely typed and therefore the double-equal comparisons may not always tell you all of the information you need.  Some further explanation here:
http://php.net/manual/en/language.types.type-juggling.php
http://php.net/manual/en/types.comparisons.php
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_12310-PHP-Variables-and-References.html

In the instant case, you probably want to be testing the return values from each function call.  You may visualize these with var_dump() to see what you're getting.

If you want to post a sample of the data you're working with and an example of the data you're trying to pull out, we may be able to help you make the conversion.
Bruce GustPHP DeveloperAuthor Commented:
Morning, Ray! As always, I appreciate your time and willingness to weigh in! I'm hoping that what I'm about to give you represents the sample of the data that you're looking for.

http://hihatwebdesign.com/test/volte.htm is the data. That html file and the info you see there is the information my code is trying to retrieve and put into a database.

This project / app was written by another very capable developer. The challenge, however, is that it was written in a deprecated version of PHP. So when I brought it over to my server, I was getting all kinds of errors (he was using mysql as opposed to mysqli) and what I thought was going to be a 15 minute copy and paste has become far more challenging.

Still, I want to hope that the architecture is sound, it's just a matter of knowing what to look for and updating things accordingly.

Having said all that, I'm hoping you've got enough info to be able to decipher my dilemma and give me some suggestions. In a minute, I'm going to post the original code that is working on his server even as we speak. And then I'll post my code with some comments that show you where I've made some changes and perhaps that will give you a better idea of where I'm missing something.

Happy Saturday!
Bruce GustPHP DeveloperAuthor Commented:
First off, here's the original code that is currently operating without a problem:

<?php
#!/usr/bin/php
//error_reporting(0);
ini_set('max_execution_time', 1200);
require '/opt/lampp/htdocs/saweb/sysperf/common.php';
echo 'STARTING PROCC VOLTE VOLTE 7 DAY TBL ' . date('h:i:s') . "<br>";

$html = file_get_contents('/opt/lampp/htdocs/upload/volte_7day.html');
mysql_query('delete from tbl_volte7');

    /*** a new dom object ***/ 
    $dom = new domDocument; 

    /*** load the html into the object ***/ 
    $dom->loadHTML($html); 

    /*** discard white space ***/ 
    $dom->preserveWhiteSpace = false; 

    /*** the table by its tag name ***/ 
    $tables = $dom->getElementsByTagName('table'); 

    /*** get all rows from the table ***/ 
    $rows = $tables->item(0)->getElementsByTagName('tr'); 

    /*** loop over the table rows ***/ 
    foreach ($rows as $row) { 
        /*** get each column by tag name ***/ 
$cols = $row->getElementsByTagName('td'); 

$enddate = $cols->item(0)->nodeValue;
$num_days = $cols->item(1)->nodeValue;
$area = $cols->item(2)->nodeValue;
$mmepool = $cols->item(3)->nodeValue;
$region = $cols->item(4)->nodeValue;
$vendor = $cols->item(5)->nodeValue;
$volte_ia_pcnt = $cols->item(6)->nodeValue;
$volte_lc_pcnt = $cols->item(7)->nodeValue;
$sip_mou = $cols->item(8)->nodeValue;
$volte_qci1_setup_failure_pcnt = $cols->item(9)->nodeValue;
$volte_qci1_setup_failures = $cols->item(10)->nodeValue;
$volte_qci1_setup_attempts = $cols->item(11)->nodeValue;
$qci5_setup_failure_pcnt = $cols->item(12)->nodeValue;
$qci5_setup_failures = $cols->item(13)->nodeValue;
$qci5_setup_attempts = $cols->item(14)->nodeValue;
$seer_pcnt = $cols->item(15)->nodeValue;
$seer_sip_ntwk_eff_calls = $cols->item(16)->nodeValue;
$seer_sip_call_attempts = $cols->item(17)->nodeValue;
$rrc_setup_failure_pcnt = $cols->item(18)->nodeValue;
$rrc_setup_attempts = $cols->item(19)->nodeValue;
$rrc_setup_failures = $cols->item(20)->nodeValue;
$volte_qci1_drop_pcnt = $cols->item(21)->nodeValue;
$volte_qci1_drops = $cols->item(22)->nodeValue;
$volte_qci1_established_calls = $cols->item(23)->nodeValue;
$qci5_bearer_drop_pcnt = $cols->item(24)->nodeValue;
$qci5_bearer_drops = $cols->item(25)->nodeValue;
$qci5_bearer_estab_calls = $cols->item(26)->nodeValue;
$volte_avg_mos = $cols->item(27)->nodeValue;
$volte_mos_numerator = $cols->item(28)->nodeValue;
$volte_mos_denominator = $cols->item(19)->nodeValue;
$volte_pdcp_dl_volume_mb = $cols->item(30)->nodeValue;
$volte_dl_volume_pcnt = $cols->item(31)->nodeValue;
$lte_pdcp_dl_volume_mb = $cols->item(32)->nodeValue;
$x7x24_volte_pdcp_dl_volume_mb = $cols->item(33)->nodeValue;
$x7x24_volte_dl_volume_pcnt = $cols->item(34)->nodeValue;
$x7x24_lte_pdcp_dl_volume_mb = $cols->item(35)->nodeValue;
$volte_pdcp_ul_volume_mb = $cols->item(36)->nodeValue;
$volte_ul_volume_pcnt = $cols->item(37)->nodeValue;
$lte_pdcp_ul_volume_mb = $cols->item(38)->nodeValue;
$x7x24_days = $cols->item(39)->nodeValue;


$ran_ia_pcnt = $volte_qci1_setup_failure_pcnt + $qci5_setup_failure_pcnt + $rrc_setup_failure_pcnt ;
$seer_ia_pcnt = 100 - $seer_pcnt;


if ($region == 'Carolinas/Tennessee') {$region = 'CAR/TN';}
if ($region == 'Central Texas') {$region = 'CTX';}
if ($region == 'Florida') {$region = 'FL';}
if ($region == 'Georgia/Alabama') {$region = 'GA/AL';}
if ($region == 'Houston/Gulf Coast') {$region = 'HGC';}
if ($region == 'South Central') {$region = 'SCTL';}

if ($enddate <> '' ){
$q1 = "insert into tbl_volte7(enddate,latest_date,area,region,vendor,ran_ia_pcnt,seer_ia_pcnt,volte_lc_pcnt,sip_mou,volte_qci1_setup_failure_pcnt,volte_qci1_setup_failures,volte_qci1_setup_attempts,qci5_setup_failure_pcnt,qci5_setup_failures,qci5_setup_attempts,seer_pcnt,seer_sip_ntwk_eff_calls,seer_sip_call_attempts,rrc_setup_failure_pcnt,rrc_setup_attempts,rrc_setup_failures,volte_qci1_drop_pcnt,volte_qci1_drops,volte_qci1_established_calls) VALUES ('$enddate','$latest_date','$area','$region','$vendor','$ran_ia_pcnt','$seer_ia_pcnt','$volte_lc_pcnt','$sip_mou','$volte_qci1_setup_failure_pcnt','$volte_qci1_setup_failures','$volte_qci1_setup_attempts','$qci5_setup_failure_pcnt','$qci5_setup_failures','$qci5_setup_attempts','$seer_pcnt','$seer_sip_ntwk_eff_calls','$seer_sip_call_attempts','$rrc_setup_failure_pcnt','$rrc_setup_attempts','$rrc_setup_failures','$volte_qci1_drop_pcnt','$volte_qci1_drops','$volte_qci1_established_calls')";

mysql_query($q1) ;

}
} 


$q2 = "select avg(ran_ia_pcnt) as area_ran_ia_pcnt, avg(seer_ia_pcnt) as area_seer_ia_pcnt, (sum(volte_qci1_drops)/sum(volte_qci1_established_calls))*100 as area_volte_lc_pcnt, sum(sip_mou) as area_sip_mou  from tbl_volte7"; 
//echo $q2  . "<br>";
$r2 = mysql_query($q2) or die(mysql_error()); 
$row1 = mysql_fetch_assoc($r2);


$area_ran_ia_pcnt = round($row1['area_ran_ia_pcnt'],3);
$area_seer_ia_pcnt = round($row1['area_seer_ia_pcnt'],3);
$area_volte_lc_pcnt = round($row1['area_volte_lc_pcnt'] ,3);
$area_sip_mou = $row1['area_sip_mou'];

$q3 = "insert into tbl_volte7 set region = 'AREA', ran_ia_pcnt = '$area_ran_ia_pcnt', seer_ia_pcnt= '$area_seer_ia_pcnt', volte_lc_pcnt = '$area_volte_lc_pcnt', sip_mou = '$area_sip_mou' "; 
//echo $q2  . "<br>";
mysql_query($q3);

mysql_close($con); 
 
echo 'COMPLETED PROCC VOLTE 7 DAY TBL ' . date('h:i:s') . "<br>";

 

?> 

Open in new window


Secondly, here is the code that I've edited in order to update the deprecated mysql stuff along with some comments to explain where I've been making some changes:

<?php
date_default_timezone_set('America/Chicago');
//I was getting some warnings on this page that seemed more about format then they did content. In an effort to keep it clean, yet accurate, I just activated "error_reporting(0)"
error_reporting(E_ALL);
ini_set('max_execution_time', 1200);
libxml_use_internal_errors(false);
//made sure that the "common.php" file was accurately point to, and connecting with, my database
require 'common.php';
echo 'STARTING PROCC VOLTE VOLTE 7 DAY TBL ' . date('h:i:s') . "<br>";

//here's the data I'm trying to retrieve. I'll send this in another post
$html = file_get_contents('../uploads/volte_7day.html');
var_dump($html);
$delete_query="delete from tbl_volte7";
//echo $delete_query;
//line 16 shows you what I had to do to bring the code up to a more contemporary level as far as updating from "mysql_query('delete from tbl_volte7');" to $query_1=mysqli_query($con, $delete_query)
$query_1 = mysqli_query($con, $delete_query);
//this is me just making sure I had a connection and I was actually interacting with my database
if(!$query_1)
{
	echo "your delete query didn't work";
}

    /*** a new dom object ***/ 
    $file = new domDocument; 
	
	/*** load the html into the object ***/ 
	//introduced "@file" to suppress invalid HTML markup warnings
	$dom=@$file->loadHTML($html); 
	
	if(!$dom)
	{
		echo "You don't have data";
	}
	    /*** discard white space ***/ 
    $file->preserveWhiteSpace = false; 

/*** the table by its tag name ***/ 
    $tables = $file->getElementsByTagName('table'); 

    /*** get all rows from the table ***/ 
    $rows = $tables->item(0)->getElementsByTagName('tr'); 

    /*** loop over the table rows ***/ 
    foreach ($rows as $row) { 
        /*** get each column by tag name ***/ 
$cols = $row->getElementsByTagName('td'); 

var_dump($cols);

$enddate = $cols->item(0)->nodeValue;
$num_days = $cols->item(1)->nodeValue;
$area = $cols->item(2)->nodeValue;
$mmepool = $cols->item(3)->nodeValue;
$region = $cols->item(4)->nodeValue;
$vendor = $cols->item(5)->nodeValue;
$volte_ia_pcnt = $cols->item(6)->nodeValue;
$volte_lc_pcnt = $cols->item(7)->nodeValue;
$sip_mou = $cols->item(8)->nodeValue;
$volte_qci1_setup_failure_pcnt = $cols->item(9)->nodeValue;
$volte_qci1_setup_failures = $cols->item(10)->nodeValue;
$volte_qci1_setup_attempts = $cols->item(11)->nodeValue;
$qci5_setup_failure_pcnt = $cols->item(12)->nodeValue;
$qci5_setup_failures = $cols->item(13)->nodeValue;
$qci5_setup_attempts = $cols->item(14)->nodeValue;
$seer_pcnt = $cols->item(15)->nodeValue;
$seer_sip_ntwk_eff_calls = $cols->item(16)->nodeValue;
$seer_sip_call_attempts = $cols->item(17)->nodeValue;
$rrc_setup_failure_pcnt = $cols->item(18)->nodeValue;
$rrc_setup_attempts = $cols->item(19)->nodeValue;
$rrc_setup_failures = $cols->item(20)->nodeValue;
$volte_qci1_drop_pcnt = $cols->item(21)->nodeValue;
$volte_qci1_drops = $cols->item(22)->nodeValue;
$volte_qci1_established_calls = $cols->item(23)->nodeValue;
$qci5_bearer_drop_pcnt = $cols->item(24)->nodeValue;
$qci5_bearer_drops = $cols->item(25)->nodeValue;
$qci5_bearer_estab_calls = $cols->item(26)->nodeValue;
$volte_avg_mos = $cols->item(27)->nodeValue;
$volte_mos_numerator = $cols->item(28)->nodeValue;
$volte_mos_denominator = $cols->item(19)->nodeValue;
$volte_pdcp_dl_volume_mb = $cols->item(30)->nodeValue;
$volte_dl_volume_pcnt = $cols->item(31)->nodeValue;
$lte_pdcp_dl_volume_mb = $cols->item(32)->nodeValue;
$x7x24_volte_pdcp_dl_volume_mb = $cols->item(33)->nodeValue;
$x7x24_volte_dl_volume_pcnt = $cols->item(34)->nodeValue;
$x7x24_lte_pdcp_dl_volume_mb = $cols->item(35)->nodeValue;
$volte_pdcp_ul_volume_mb = $cols->item(36)->nodeValue;
$volte_ul_volume_pcnt = $cols->item(37)->nodeValue;
$lte_pdcp_ul_volume_mb = $cols->item(38)->nodeValue;
$x7x24_days = $cols->item(39)->nodeValue;


$ran_ia_pcnt = $volte_qci1_setup_failure_pcnt + $qci5_setup_failure_pcnt + $rrc_setup_failure_pcnt ;
$seer_ia_pcnt = 100 - $seer_pcnt;


if ($region == 'Carolinas/Tennessee') {$region = 'CAR/TN';}
if ($region == 'Central Texas') {$region = 'CTX';}
if ($region == 'Florida') {$region = 'FL';}
if ($region == 'Georgia/Alabama') {$region = 'GA/AL';}
if ($region == 'Houston/Gulf Coast') {$region = 'HGC';}
if ($region == 'South Central') {$region = 'SCTL';}

if ($enddate <> '' ){
$q1 = "insert into tbl_volte7(enddate,latest_date,area,region,vendor,ran_ia_pcnt,seer_ia_pcnt,volte_lc_pcnt,sip_mou,volte_qci1_setup_failure_pcnt,volte_qci1_setup_failures,volte_qci1_setup_attempts,qci5_setup_failure_pcnt,qci5_setup_failures,qci5_setup_attempts,seer_pcnt,seer_sip_ntwk_eff_calls,seer_sip_call_attempts,rrc_setup_failure_pcnt,rrc_setup_attempts,rrc_setup_failures,volte_qci1_drop_pcnt,volte_qci1_drops,volte_qci1_established_calls) VALUES ('$enddate','$latest_date','$area','$region','$vendor','$ran_ia_pcnt','$seer_ia_pcnt','$volte_lc_pcnt','$sip_mou','$volte_qci1_setup_failure_pcnt','$volte_qci1_setup_failures','$volte_qci1_setup_attempts','$qci5_setup_failure_pcnt','$qci5_setup_failures','$qci5_setup_attempts','$seer_pcnt','$seer_sip_ntwk_eff_calls','$seer_sip_call_attempts','$rrc_setup_failure_pcnt','$rrc_setup_attempts','$rrc_setup_failures','$volte_qci1_drop_pcnt','$volte_qci1_drops','$volte_qci1_established_calls')";
echo $q1;
$insert = mysqli_query($con, $q1) ;
if(!$insert)
{
	echo "your insert query didn't happen";
}

}
} 


$q2 = "select avg(ran_ia_pcnt) as area_ran_ia_pcnt, avg(seer_ia_pcnt) as area_seer_ia_pcnt, (sum(volte_qci1_drops)/sum(volte_qci1_established_calls))*100 as area_volte_lc_pcnt, sum(sip_mou) as area_sip_mou  from tbl_volte7"; 
//echo $q2  . "<br>";
$r2 = mysql_query($q2) or die(mysql_error()); 
$row1 = mysql_fetch_assoc($r2);


$area_ran_ia_pcnt = round($row1['area_ran_ia_pcnt'],3);
$area_seer_ia_pcnt = round($row1['area_seer_ia_pcnt'],3);
$area_volte_lc_pcnt = round($row1['area_volte_lc_pcnt'] ,3);
$area_sip_mou = $row1['area_sip_mou'];

$q3 = "insert into tbl_volte7 set region = 'AREA', ran_ia_pcnt = '$area_ran_ia_pcnt', seer_ia_pcnt= '$area_seer_ia_pcnt', volte_lc_pcnt = '$area_volte_lc_pcnt', sip_mou = '$area_sip_mou' "; 
//echo $q2  . "<br>";
$insert_2=mysqli_query($con, $q3);
if(!$insert_2)
{
	echo "your averages didn't work";
}

mysql_close($con); 
 
echo 'COMPLETED PROCC VOLTE 7 DAY TBL ' . date('h:i:s') . "<br>";

 

?> 

Open in new window


I've got the html file that's referenced in the code attached.
volte-7day.html
Ray PaseurCommented:
Couple of things... You can find the PHP changelog and it will give you a heads-up about changes in the language platform.  For example, if you're working with PHP 5+, you can find a list of release-to-release changes here.  I know that is a lot to read, but it's just something we have to do if we're going to work with PHP.
http://php.net/ChangeLog-5.php

Let's tackle the MySQL part of the modernization first.  There may be other things that need to change, but a one-for-one replacement that swaps out MySQL for MySQLi would be a good first step.

This article shows how I would go about converting an existing MySQL installation to MySQLi.  I would use the OOP notation for MySQLi because it's the easier conversion for old MySQL code.  Let's consider this query:

mysql_query('delete from tbl_volte7');

If you've made the OOP MySQLi connection and you named it "$mysqli" your code change will look like this.  Parallel construction to the existing function calls, and very little difference in syntax:

$mysqli->query('delete from tbl_volte7');

While you're making the MySQL part of the modernization, it's comforting to know that you can get two MySQL connections to the same data base, keeping the old connection and adding the new object-oriented connection.  This means you can convert the queries one-at-a-time.  In the old script I see this line:

require '/opt/lampp/htdocs/saweb/sysperf/common.php';

My guess is that script contains the "initialization" code for this app - settings, constants, database connection, etc.  That is where I would put my first attention.  If you can add or subtract from that "common" script and get the app working, it would be great.  You might add a MySQLi connection there and then remediate the instances that call the deprecated extension.  These are on lines 9, 87, 95, 96, 106, 108.  Line 108 isn't needed, so there are really only 5 lines that need to change for this part of the work.

You might try doing that with the old script - nothing more - then revisit any other issues that still persist.  You may need some changes in PHP settings, etc., to get it all to work, but if you try to eat the elephant one bite at a time it will be easier.
Bruce GustPHP DeveloperAuthor Commented:
Ray, I'm applying your wisdom and I'm at a point where I want your "eyes."

I went back and changed things so I'm now in line with your suggestion as far as $con->query('delete from tbl_volte7') etc., so that's done.

I've broken the code down to this:

date_default_timezone_set('America/Chicago');
#!/usr/bin/php
//error_reporting(0);
ini_set('max_execution_time', 1200);
require 'common.php';
echo 'STARTING PROCC VOLTE VOLTE 7 DAY TBL ' . date('h:i:s') . "<br>";

$html = file_get_contents('http://southareanetwork.nss.vzwnet.com/weekly_reports/uploads/volte_7day.html');
$con->query('delete from tbl_volte7');

    /*** a new dom object ***/ 
    $dom = new domDocument; 

    /*** load the html into the object ***/ 
    $dom->loadHTML($html); 

    /*** discard white space ***/ 
    $dom->preserveWhiteSpace = false; 

    /*** the table by its tag name ***/ 
    $tables = $dom->getElementsByTagName('table'); 

    /*** get all rows from the table ***/ 
    $rows = $tables->item(0)->getElementsByTagName('tr'); 
if($rows)
{
echo "OK";
}

Open in new window


What I get when I run that is the following:

Warning: DOMDocument::loadHTML(): htmlParseStartTag: misplaced tag in Entity, line: 3 in /var/www/html/sasite/weekly_reports/procedures/procc_volte_7day.php on line 16 Warning: DOMDocument::loadHTML(): htmlParseStartTag: misplaced tag in Entity, line: 4 in /var/www/html/sasite/weekly_reports/procedures/procc_volte_7day.php on line 16 Warning: DOMDocument::loadHTML(): htmlParseStartTag: misplaced tag in Entity, line: 25 in /var/www/html/sasite/weekly_reports/procedures/procc_volte_7day.php on line 16 Warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity, line: 30 in /var/www/html/sasite/weekly_reports/procedures/procc_volte_7day.php on line 16 Warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity, line: 30 in /var/www/html/sasite/weekly_reports/procedures/procc_volte_7day.php on line 16 Warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity, line: 30 in /var/www/html/sasite/weekly_reports/procedures/procc_volte_7day.php on line 16 Warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity, line: 30 in /var/www/html/sasite/weekly_reports/procedures/procc_volte_7day.php on line 16 Warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity, line: 30 in /var/www/html/sasite/weekly_reports/procedures/procc_volte_7day.php on line 16 Warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity, line: 30 in /var/www/html/sasite/weekly_reports/procedures/procc_volte_7day.php on line 16 Warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity, line: 30 in /var/www/html/sasite/weekly_reports/procedures/procc_volte_7day.php on line 16 Warning: DOMDocument::loadHTML(): htmlParseEntityRef: expecting ';' in Entity, line: 30 in /var/www/html/sasite/weekly_reports/procedures/procc_volte_7day.php on line 16 OK 

Open in new window


Now I can suppress those errors by doing this:

<?php
date_default_timezone_set('America/Chicago');
#!/usr/bin/php
//error_reporting(0);
ini_set('max_execution_time', 1200);
require 'common.php';
echo 'STARTING PROCC VOLTE VOLTE 7 DAY TBL ' . date('h:i:s') . "<br>";

$html = file_get_contents('http://southareanetwork.nss.vzwnet.com/weekly_reports/uploads/volte_7day.html');
$con->query('delete from tbl_volte7');

    /*** a new dom object ***/ 
    $file = new domDocument; 

    /*** load the html into the object ***/ 
    $dom=@$file->loadHTML($html); 

    /*** discard white space ***/ 
    $file->preserveWhiteSpace = false; 

    /*** the table by its tag name ***/ 
    $tables = $file->getElementsByTagName('table'); 

    /*** get all rows from the table ***/ 
    $rows = $tables->item(0)->getElementsByTagName('tr'); 
if($rows)
{
echo "OK";
}
?> 

Open in new window


The main changes being:

$file=new domDocument; //line 13

$dom=@$file->loadHTML($html);  //line 16

But my concern is that I'm overlooking something because I just feel like since this is "working code," for me to have to introduce something so soon in the syntax coupled with the fact that I seem to be lacking an "object" when I get a little further down the line, I don't know. Does anything look sinister to you at this point?
$dom=@$file->loadHTML($html);
Ray PaseurCommented:
I recommend you revert the entire script to the original, then fix only the MySQL part -- only the five lines we identified above.  Keep everything else intact, especially the DOM part.  Once that is done, move on to the next part of the work.  

Also, I find that I almost never want the @ notation to suppress error messages - if there's an error, it's better to fix the error than hide the message.  Using @ is AntiPractice #5.  There was no @ in the original script; there should not be one in your script either.
Bruce GustPHP DeveloperAuthor Commented:
Ray, I think I've found something:

When I run the first query, I get an error message that says:

Out of range value for column 'qci5_setup_attempts' at row 1

The datatype is int(11) and the actual value is 5237420333;

Even when I do this: "insert into tbl_volte7(qci5_setup_attempts) VALUES ('5237420333')" I get that error. Why am I getting that error?
Ray PaseurCommented:
Here's an explanation of the error.
http://dev.mysql.com/doc/refman/5.5/en/out-of-range-and-overflow.html

Max value in a 32-bit integer: 2,147,483,647.  Your value: 5,237,420,333.  Possible solutions might include changing the data type from INT to BIGINT or BIGINT UNSIGNED.

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
Bruce GustPHP DeveloperAuthor Commented:
Changed datatype to BIGINT(15) and am getting the same error.

What am I missing?
Bruce GustPHP DeveloperAuthor Commented:
Never mind. Hang on...
Bruce GustPHP DeveloperAuthor Commented:
Got it!

Thanks!
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.