ayok Posted March 1, 2009 Share Posted March 1, 2009 Hi, I have a php webstore application that has been used for php4. Now I'm trying to migrate those scripts to php5 server, and I've got problem. The scripts doesn't work. I knew this would be happened, but i'll try to fix the errors. There are a lot of notices and i see no fatal errors, but it still doesn't work. Now I'm stuck with this:Notice: Undefined property: stdClass::$language in /var/www/vhosts/WEBSHOP/WEBSHOP_OUTPUT/Control/LanguageControl.php on line 12. There is a class on this line, which I guess the cause of these errors. <?php class LanguageControl{ function retrieveSet($lang) { $arr = array(); $lang = $language; $a = mysql_query("SELECT * FROM LanguageSet"); while($b = mysql_fetch_object($a)) { $arr[$b->key] = $b->$language; } return $arr; } } ?> I'm a newbie for oop. Any help would be appriciated. thank you, ayok Quote Link to comment https://forums.phpfreaks.com/topic/147448-php4-to-php5/ Share on other sites More sharing options...
wildteen88 Posted March 1, 2009 Share Posted March 1, 2009 $b->$language; Should be $b->language; Quote Link to comment https://forums.phpfreaks.com/topic/147448-php4-to-php5/#findComment-773946 Share on other sites More sharing options...
Mchl Posted March 1, 2009 Share Posted March 1, 2009 change $arr[$b->key] = $b->$language; to if (isset($b->$language)) { $arr[$b->key] = $b->$language; } Quote Link to comment https://forums.phpfreaks.com/topic/147448-php4-to-php5/#findComment-773947 Share on other sites More sharing options...
ayok Posted March 2, 2009 Author Share Posted March 2, 2009 Thank you for the helps. Now I'm stuck with this message: Notice: Trying to get property of non-object in ... everytime there is these codes: <?php $sql = "SELECT * FROM Products WHERE id = '".$id."'"; $do = mysql_query($sql); $o = mysql_fetch_object($do); $artNr = $o->artNr; ?> Can anyone tell me how should I write it? Quote Link to comment https://forums.phpfreaks.com/topic/147448-php4-to-php5/#findComment-775037 Share on other sites More sharing options...
Mchl Posted March 2, 2009 Share Posted March 2, 2009 add var_dump($o); just before $artNr = $o->artNr; and tell us what it says. Quote Link to comment https://forums.phpfreaks.com/topic/147448-php4-to-php5/#findComment-775038 Share on other sites More sharing options...
trq Posted March 2, 2009 Share Posted March 2, 2009 There is nothing particularly wrong with that piece of code excepting that your query may be failing or returning no results and you fail to check it. Where is $id defined? You code would be better written.... <?php $sql = "SELECT * FROM Products WHERE id = '".$id."'"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $o = mysql_fetch_object($do); $artNr = $o->artNr; } // handle no results } // handle query failure ?> Quote Link to comment https://forums.phpfreaks.com/topic/147448-php4-to-php5/#findComment-775041 Share on other sites More sharing options...
ayok Posted March 2, 2009 Author Share Posted March 2, 2009 add var_dump($o); just before $artNr = $o->artNr; and tell us what it says. It says:bool(false) Quote Link to comment https://forums.phpfreaks.com/topic/147448-php4-to-php5/#findComment-775086 Share on other sites More sharing options...
trq Posted March 2, 2009 Share Posted March 2, 2009 Your query is failing. Where is $id defined? Quote Link to comment https://forums.phpfreaks.com/topic/147448-php4-to-php5/#findComment-775087 Share on other sites More sharing options...
Mchl Posted March 2, 2009 Share Posted March 2, 2009 Possibly a register_globals issue, I'm surprised however, that mysql_fetch_object() doesn't throw a warning. Quote Link to comment https://forums.phpfreaks.com/topic/147448-php4-to-php5/#findComment-775091 Share on other sites More sharing options...
ayok Posted March 2, 2009 Author Share Posted March 2, 2009 Yes I'm trying to move scripts from php4 to php5. I have to change some $var into $_GET['var'] or $_POST['var']. Is this the cause? Quote Link to comment https://forums.phpfreaks.com/topic/147448-php4-to-php5/#findComment-775096 Share on other sites More sharing options...
Mchl Posted March 2, 2009 Share Posted March 2, 2009 If the $id comes from a HTML form, or from url request, then yes. That is most likely the cause. Quote Link to comment https://forums.phpfreaks.com/topic/147448-php4-to-php5/#findComment-775101 Share on other sites More sharing options...
ayok Posted March 3, 2009 Author Share Posted March 3, 2009 Hey thanks. But i'm still stuck. This $o is error is in a function. I'd better post the whole function here. <?php function retrieveProductModelById($id) { $sql = "SELECT * FROM Products WHERE id = '".$id."'"; $do = mysql_query($sql) or die (mysql_error()); $o = mysql_fetch_object($do); //var_dump($o); --> bool(false) $artNr = $o->artNr; $pm = new ProductModel(); if(mysql_num_rows($do)){ $pm->setId($o->id); $pm->setName($o->name); $pm->setPrice($o->price); $pm->setSale($o->sale); $pm->setSaleActive($o->saleActive); $pm->setArtNr($o->artNr); $pm->setPosition($o->position); $pm->setVisibility($o->visibility); $pm->setMenuId($o->menuId); $pm->setBTWPerc($o->BTWPerc); $pm->setDescription(stripslashes($o->description)); } $sql = "SELECT * FROM Images WHERE prodId = '".$o->artNr."'"; $do = mysql_query($sql); while($o = mysql_fetch_object($do)){ $pm->setImages($o->name); } $sql = mysql_query("SELECT * FROM ProductAliases WHERE prodId = '".$artNr."'"); while($fetch = mysql_fetch_object($sql)) { if($fetch->language == "EN") $pm->setNameEN(stripslashes($fetch->alias)); if($fetch->language == "DU") $pm->setNameDU(stripslashes($fetch->alias)); if($fetch->language == "FR") $pm->setNameFR(stripslashes($fetch->alias)); } $sql = mysql_query("SELECT * FROM ProductDescriptions WHERE prodId = '".$artNr."'") or die(mysql_error()); while($fetch = mysql_fetch_object($sql)) { if($fetch->language == "EN") $pm->setDescriptionEN(stripslashes($fetch->description)); if($fetch->language == "DU") $pm->setDescriptionDU(stripslashes($fetch->description)); if($fetch->language == "FR") $pm->setDescriptionFR(stripslashes($fetch->description)); } return $pm; } ?> More hints? Thank you in advanced. Quote Link to comment https://forums.phpfreaks.com/topic/147448-php4-to-php5/#findComment-775659 Share on other sites More sharing options...
ayok Posted March 3, 2009 Author Share Posted March 3, 2009 It's solved. Well.. not completely. Still one more Notice: Undefined offset: 1: And it's always this line: <?php function roundToTwoDecimals($price){ $price = round($price, 2); $p = explode(".",$price); if(strlen($p[1]) == 0) ---------> this line $price = $p[0].".00"; else if(strlen($p[1]) == 1) $price = $p[0].".".$p[1]."0"; return str_replace(".",",",$price); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/147448-php4-to-php5/#findComment-775799 Share on other sites More sharing options...
premiso Posted March 3, 2009 Share Posted March 3, 2009 if (isset($p[1])) { if(strlen($p[1]) == 0) $price = $p[0].".00"; else if(strlen($p[1]) == 1) $price = $p[0].".".$p[1]."0"; } Basically $p[1] was not being populated, for whatever reason. You may want to look into that. This should solve that issue either way. Quote Link to comment https://forums.phpfreaks.com/topic/147448-php4-to-php5/#findComment-775804 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.