Jump to content

php4 to php5


ayok

Recommended Posts

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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);
}
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.