Link to home
Start Free TrialLog in
Avatar of APD Toronto
APD TorontoFlag for Canada

asked on

Fatal error: Can't use function return value in write context

Hi Experts,

Why do I keep getting:
Fatal error: Can't use function return value in write context

...when I:
   if(isset($_POST["email"]) || !empty(trim($_POST["email"])))
   {
       $strEmail = $_POST["email"];
   }
   else 
   {
       $err = 1;
   }

Open in new window


Thank you.
Avatar of Gary
Gary
Flag of Ireland image

if(isset($_POST["email"]) && !empty(trim($_POST["email"])))
Avatar of APD Toronto

ASKER

makes logical sense - thanks, but same error
What is the whole function
nothing too complex... The error is at Li.40

<?php

    $submit = '';
    $err = 0;
   
    $strName = '';
    $strEmail = '';
    $strSelect = '';
    $strMessage = '';
   
    
    if(isset($_GET["submit"]))
    {
        $submit = $_GET["submit"];
    }
 
    if($submit == '')
    {
        displayForm();
    }
    else 
    {
        validate();
    }

function validate()
{    
   global $err;
   
   global $strName;
   global $strEmail;
   global $strSelect;
   global $strMessage;
   
   if(isset($_POST["name"]))
   {
       $strName = $_POST["name"];
   }
   
   if(isset($_POST["email"]) && !empty(trim($_POST["email"])))
   {
       $strEmail = $_POST["email"];
   }
   else 
   {
       $err = 1;
   }
   
   if(isset($_POST["selection"]))
   {
       $strSelect = $_POST["selection"];
   }
   else
   { 
       $err = 1;
   }
   
   if(isset($_POST["message"]) && !empty(trim($_POST["message"])))
   {
       $strMessage = $_POST["message"];
   }
   else 
   {
       $err = 1;
   }
   
   if($err = 1)
   {
       displayForm();       
   }
   else
   {
       sendEmail();
   }    
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ahmed Merghani
Ahmed Merghani
Flag of Sudan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
As a general rule, compound statements with multiple function calls in the same line of code are a path to confusion.  I believe this statement is causing the problem:

empty(trim($_POST["email"]))

Try something more like this:

$email = trim($_POST['email']);
if (empty($email)) /* DO SOMETHING */

Long ago, PHP allowed this sort of thing, but it's not allowed any more.  That's one of the risks of getting old bits of code from the internet - you don't really know if it works.  Maybe it used to work and doesn't any more.