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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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-

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.