Solved

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

Posted on 2014-09-26
6
784 Views
Last Modified: 2014-09-26
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.
0
Comment
Question by:APD_Toronto
6 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40346657
if(isset($_POST["email"]) && !empty(trim($_POST["email"])))
0
 

Author Comment

by:APD_Toronto
ID: 40346664
makes logical sense - thanks, but same error
0
 
LVL 58

Expert Comment

by:Gary
ID: 40346668
What is the whole function
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:APD_Toronto
ID: 40346673
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

0
 
LVL 8

Accepted Solution

by:
Ahmed Merghani earned 500 total points
ID: 40346674
Your code should be changed to something like this:
if(isset($_POST["email"]) && (trim($_POST["email"]) != false))
   {
       $strEmail = $_POST["email"];
   }
   else 
   {
       $err = 1;
   }

Open in new window

Prior to PHP 5.5, empty() only supports variables; anything else will result in a parse error. In other words, the following will not work: empty(trim($name)). Instead, use trim($name) == false.
See this link:
http://us3.php.net/manual/en/function.empty.php
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40346678
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.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now