Jump to content

Can't use function return value in write context


myrddinwylt

Recommended Posts

Here is a bizzare error.....

 

if(trim($cost . "") == "") { $cost = "0"; }

 

Sometimes returns the following error in the browser :  WTF!!

Fatal error: Can't use function return value in write context in C:\server\websites\127.0.0.1\htdocs-ssl\cdrdownloader\mysql.class.php on line 95

@ChemicalBliss:  Yes, that is a typo in my post here only. The actual code contains "==" for the comparison.

 

@harristweed:  I do it this way as it is getting a value set from the database, which could be multiple blank spaces, or a null, but ideally I wish it to always be numeric.

 

The code where the variable is being set is as follows:

 

    function dumpsql($daydownloaded) {
	$con = mysql_connect($this->server,$this->username,$this->password) or die(mysql_error());
	$sql = '';
	set_time_limit(3600);
	if ($con !== false){
		mysql_select_db($this->database);
		$query="SELECT * FROM `" . $this->database_temp . "`.`" . substr($daydownloaded,0,-3) . "` ORDER BY `Started` ASC;";
		$result=mysql_query($query,$con) or die(mysql_error());
		$num=mysql_numrows($result);
		$i=0;

            if ($num > $i) {
              $sql[] = "CREATE TABLE IF NOT EXISTS `" . $this->database . "`.`" . substr($daydownloaded,0,-3) . "` (`uniqueid` int(11) NOT NULL AUTO_INCREMENT, `Caller` varchar(255) DEFAULT NULL, `Started` datetime DEFAULT NULL, `Dialed` varchar(255) DEFAULT NULL, `DurationSec` int(11) DEFAULT NULL, `DurationMin` int(11) DEFAULT NULL, `Cost` double DEFAULT NULL, `Location` varchar(60) DEFAULT NULL, `Switch` varchar(15) DEFAULT NULL, PRIMARY KEY (`uniqueid`)) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;";
              $sql[] = "DELETE FROM `" . $this->database . "`.`" . substr($daydownloaded,0,-3) . "` WHERE `Started` LIKE '" . $daydownloaded . "%';";
            }

		while ($i < $num) {
			$caller      = mysql_result($result,$i,"Caller");
			$started     = mysql_result($result,$i,"Started");
			$dialed      = mysql_result($result,$i,"Dialed");
			$durationsec = mysql_result($result,$i,"DurationSec");
			$durationmin = mysql_result($result,$i,"DurationMin");
			$cost        = mysql_result($result,$i,"Cost");
                if(trim($cost . "") == "") { $cost = "0"; }
			$location    = mysql_result($result,$i,"Location");
                $switch      = mysql_result($result,$i,"Switch");
			$sql[] = "INSERT INTO `" . $this->database . "`.`" . substr($daydownloaded,0,-3) . "` VALUES(null, '" . $caller  . "', '" . $started . "', '" . $dialed  . "', " . $durationsec  . ", " . $durationmin . ", " . $cost . ",'" . $location . "','" . $switch . "');";
			$i++;
		}
		mysql_close($con);
        }
        unset($con, $caller, $started, $dialed, $durationsec, $durationmin, $cost, $location, $switch);
        return $sql;
    }

 

This error occurs only when the condition is met.

Hmm, i cannot reproduce this error without using a single = operator. So i cannot help you in that respect, maybe do a quick search on php bugs see if someone has posted already , if not then psot with as much info as possible so they can try to reproduce it.

 

for now though, i would do this part like this:

if(!is_numeric($cost)) { $cost = "0"; }

 

-cb-

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.