divadiva Posted June 18, 2008 Share Posted June 18, 2008 Experts I ran my system in localhost it works absolutely fine.But now I have shifted it to production server.I get these warning which I am unable to figure out: Notice: Trying to get property of non-object in /var/www/html/site.php on line 80.This is driving me insane. Here is my code of this site: <?php include("mainpage.php"); include_once("database.php"); set_time_limit(0); parseData(); function parseData() { handlOldData('BB'); $content = geCurlContent("http://"); if (preg_match_all("/auctionList.taf\?sid=133&m=(.*?)&sort=manufacturer&_UserReference=/si", $content, $array)) { $i=0; $eachLink = "http://auctionList.taf?sid=133&m=VALUE&sort=manufacturer"; while($i<count($array[1])) //iterate over all match of the links which contains our desired data { $actualLink = str_replace('VALUE', $array[1][$i], $eachLink); callEachPage($actualLink); //call function for each of these pages // echo '<br/>'.$actualLink; $i++; } } } function geCurlContent($link) { // initialize curl $ch = curl_init(); // set the url to fetch curl_setopt($ch, CURLOPT_URL, $link); // don't give me the headers just the content curl_setopt($ch, CURLOPT_HEADER, 0); // return the value instead of printing the response to browser curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // write data to variable $content = curl_exec($ch); // close curl curl_close($ch); return $content; } function callEachPage($link) { //echo $link; $content = geCurlContent($link); //we get the expected page. now need parse to save actual data in db /* * matching a specific patter so that we get a 2D array $array. Here we will only find out our expected table portion. */ if(preg_match_all("/<TABLE WIDTH=\"100%\" CELLPADDING=2 CELLSPACING=1 BORDER=0 CLASS=color>(.*?)<\/table>/si", $content, $array)) { $content = '<table>'.str_replace("&", "&", $array[1][0]).'</table>'; } //now the table portion will be passed to domdocument to parse each column $dom = new DOMDocument(); //dom document object $dom->loadHTML($content); //load the tbody part // find all tables $tables = $dom->getElementsByTagName('table'); // get all rows from the first table $rows = $tables->item(0)->getElementsByTagName('tr'); foreach ($rows as $row) //for each tr { $cols = $row->getElementsByTagName('td'); //get columns for the current row if(strlen($cols->item(2)->nodeValue)) //if has at least manufacturer { if(checkExists('BB', $cols->item(0)->nodeValue) == 0) { //build insert query $query = "insert into data(WebsiteId, Process, Manufacturer, Model, Wafersize, Serial, ProductionYear, Site, onmarket) values"; $query .= "('".trim($cols->item(0)->nodeValue)."', '".$cols->item(1)->nodeValue."', '".$cols->item(2)->nodeValue."', '".$cols->item(4)->nodeValue."', '".$cols->item(5)->nodeValue."', '', '".$cols->item(6)->nodeValue."', 'BBEM', 1)"; //print '<br/>'.$query; executeNonQuery($query); //execute the insert query } } } } echo 'Data parsed and saved successfully.'; include("footer.php"); ?> Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/110749-solved-how-to-get-rid-of-this-warning-when-my-code-is-working-fine/ Share on other sites More sharing options...
rarebit Posted June 18, 2008 Share Posted June 18, 2008 Not sure which line 80 is? But, array elements are accessed using square brackets not parenthesis... e.g. [] not () (* * * don't quote me, I could be mistaken) Link to comment https://forums.phpfreaks.com/topic/110749-solved-how-to-get-rid-of-this-warning-when-my-code-is-working-fine/#findComment-568151 Share on other sites More sharing options...
Jabop Posted June 18, 2008 Share Posted June 18, 2008 Without copying/pasting the code into an editor myself, could you point out line 80? Link to comment https://forums.phpfreaks.com/topic/110749-solved-how-to-get-rid-of-this-warning-when-my-code-is-working-fine/#findComment-568152 Share on other sites More sharing options...
divadiva Posted June 18, 2008 Author Share Posted June 18, 2008 Thanks for replying LINE 80: if(strlen($cols->item(2)->nodeValue) I have fixed this issue temporarily by turning the debugger OFF. But still not sure why that error came. Link to comment https://forums.phpfreaks.com/topic/110749-solved-how-to-get-rid-of-this-warning-when-my-code-is-working-fine/#findComment-568171 Share on other sites More sharing options...
Jabop Posted June 18, 2008 Share Posted June 18, 2008 If you have the code working properly and there are no errors, I wouldn't worry about it. PHP with all error msgs on is very strict. Link to comment https://forums.phpfreaks.com/topic/110749-solved-how-to-get-rid-of-this-warning-when-my-code-is-working-fine/#findComment-568174 Share on other sites More sharing options...
divadiva Posted June 18, 2008 Author Share Posted June 18, 2008 Thanks! Link to comment https://forums.phpfreaks.com/topic/110749-solved-how-to-get-rid-of-this-warning-when-my-code-is-working-fine/#findComment-568175 Share on other sites More sharing options...
rarebit Posted June 18, 2008 Share Posted June 18, 2008 try printing out, see if has a node, if not wrap it like you have the next line... print_r($cols->item(2)->nodeValue); if(strlen($cols->item(2)->nodeValue)) //if has at least manufacturer { if(checkExists('BB', $cols->item(0)->nodeValue) == 0) { Link to comment https://forums.phpfreaks.com/topic/110749-solved-how-to-get-rid-of-this-warning-when-my-code-is-working-fine/#findComment-568178 Share on other sites More sharing options...
divadiva Posted June 18, 2008 Author Share Posted June 18, 2008 I tried that works fine. Link to comment https://forums.phpfreaks.com/topic/110749-solved-how-to-get-rid-of-this-warning-when-my-code-is-working-fine/#findComment-568186 Share on other sites More sharing options...
divadiva Posted June 18, 2008 Author Share Posted June 18, 2008 Experts Thanks for the suggestions. Link to comment https://forums.phpfreaks.com/topic/110749-solved-how-to-get-rid-of-this-warning-when-my-code-is-working-fine/#findComment-568191 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.