I am trying to run code from a book . There seems to be a problem with the code.
Here is the error message:
Fatal error: you cannot use the return function value in the context of the entry in / Applications / MAMP / htdocs / Eclipse -Workspace / simpleblog / test.php on line 24
Here is the code indicated in the message (starting at 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! <br />", "Username: $uname <br />", "Email: $email <br />"; }
I would be grateful for any help. Please let me know if I need to provide more information.
Thanks a lot guys. It was very fast. The solution works great.
The problem is that the empty () function should only be applied to direct variables.
For future reference: Code from "PHP for Absolute Beginners" by Jason Lengstorf (2009), pages 90-91, chapter 3, $ _SESSION
fixed code:
//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! <br />", "Username: $uname <br />", "Email: $email <br />"; }
ntc
source share