/    Sign up×
Community /Pin to ProfileBookmark

Fatal errror–help!

Thanks in advance for reading the post and any help u can provide.

I get the following error

[B]“Fata error: Cant use function value in write contect”[/B] the line of code involved appears to be the following:

if(!empty(trim($_POST[‘username’]))

its a validation script

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NogDogNov 28.2009 — The parameter for empty() must be a variable, not a function call. How about:
[code=php]
if(trim($_POST['username']) !== '');
[/code]
Copy linkTweet thisAlerts:
@ServauxauthorNov 28.2009 — Thanks NogDog...seems like I should have posted the rest of the code...I made that change and then I had syntax errors on three lines

Here is the orignal code in its entirety,

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 />";

}

else {
echo "Please fill out both fields! <br />";

}
}


else {

?>

it shows no erros until I check it in a browser and that when I get the fatal error
Copy linkTweet thisAlerts:
@NogDogNov 28.2009 — Please make use of this forum's [noparse][code=php]...[/code][/noparse] tags when posting PHP code samples: it makes life much easier on those who might want to help.

The opening if condition would need to be something like:
[code=php]
if(trim($_POST['username']) !== '' && trim($_POST['email']) !== '') {
[/code]

As to the rest, the curly braces do not balance out, but I'm guessing that may be due to not having all the code here, so I don't know if it's a problem or not.
Copy linkTweet thisAlerts:
@ServauxauthorNov 28.2009 — Hi NogDog thanks for your help I have implemented the changes and receive new syntax errors. configuring some of the curly braces only generated more erros starting with $uname and my else statement above the echo"please fill out both fields!"

Here is the code
[code=php] <?php

// Initialize session data
session_start();

/*
* If the user is already registered, display a
* message letting them know.
*/
if(isset($_SESSION['username'])) {
echo "You're already registered as $_SESSION[username].";
}

// Checks if the form was submitted
else if($_SERVER['REQUEST_METHOD'] == 'POST') {


}
if(trim($_POST['username']) !== ''
&& (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 />";

}
/*
* If the user did not fill out both fields, display
* a message letting them know that both fields are
* required for registration.
*/
else {
echo "Please fill out both fields! <br />";
}
}

// If the form was not submitted, displays the form HTML
else {

? [/code]
×

Success!

Help @Servaux spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...