php 5.3 - Error message: Fatal error: Can't use function return > value in write context in -
i trying run code book. there appears problem code.
here error message:
fatal error: can't use function return value in write context in /applications/mamp/htdocs/eclipse-workspace/simpleblog/test.php on line 24
here code referenced in 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 registering! <br />", "username: $uname <br />", "email: $email <br />"; }
i appreciate help. please let me know if need provide more information
thanks lot guys. fast. solution works great.
the problem empty() function needs applied direct variables.
for future reference: code 'php absolute beginners' jason lengstorf (2009), pages 90-91, chapter 3, $_session
corrected code:
//new - created variable can passed empty() function $trimusername = trim($_post['username']); //modified - applying empty function correctly 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 registering! <br />", "username: $uname <br />", "email: $email <br />"; }
in short: empty()
function works directly on variables
<?php empty($foo); // ok empty(trim($foo)); // not ok
i'd say, course of getting further book, use temporary variable
so change:
if (!empty(trim($_post['username']))
to
$username = trim($_post['username']); if(!empty($username)) { //....
Comments
Post a Comment