Сообщение об ошибке: Неустранимая ошибка: Невозможно использовать значение функции return> в контексте записи в

Я пытаюсь запустить некоторый код из книги . Похоже, возникла проблема с кодом.

Вот сообщение об ошибке:

Неустранимая ошибка: невозможно использовать возврат функции значение в контексте записи в /Applications/MAMP/htdocs/Eclipse-Workspace/simpleblog/test.php on line 24

Here is the code referenced in the message (starting on line 24)

if (!empty(trim($_POST['username'])) 
        && !empty(trim($_POST['email']))) { 
        // Store escaped $_POST values in variables 
            $uname = htmlentities($_POST['username']); 
            $email = htmlentities($_POST['email']); 

            $_SESSION['username'] = $uname; 

            echo "Thanks for registering! 
", "Username: $uname
", "Email: $email
"; }

I would appreciate any help. Please let me know if I need to provide any more information


Thanks a lot guys. That was very fast. The solution works great.

The problem is that the empty() function needs to be applied only to direct variables.

For future reference: Код взят из «PHP для абсолютных новичков» Джейсона Ленгсторфа (2009), страницы 90-91, глава 3, $ _SESSION

исправленный код:

    //new - Created a variable that can be passed to the empty() function
    $trimusername = trim($_POST['username']);

    //modified - applying the empty function correctly to the new variable 
    if (!empty($trimusername) 
    && !empty($trimusername)) { 

    // Store escaped $_POST values in variables 
    $uname = htmlentities($_POST['username']); 
    $email = htmlentities($_POST['email']); 

    $_SESSION['username'] = $uname; 

    echo "Thanks for registering! 
", "Username: $uname
", "Email: $email
"; }

6
задан ntc 16 November 2010 в 09:24
поделиться