/    Sign up×
Community /Pin to ProfileBookmark

help with rogue comment field if usuage

This is stumping me.

What I want it to do is check that there is something in the content field. if not then it should not write out a comment to the file. The problem is that writes the blank comment form.

can anyone shed some light on this?

[CODE]if (isset($comment))
{
$newComment= “<P><a href=”mailto:$email”>$name</a> said on $today<br>$comment</P>”;
$theCommentFileName = $survey.”comments.inc”;
if (file_exists($theCommentFileName)){$FH = fopen($theCommentFileName, “a”);}
else{$FH = fopen($theCommentFileName, “x”);}

fwrite($FH,$newComment);
fclose($FH);[/CODE]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@Big_JayauthorFeb 22.2007 — figured it out. I used a if(!empty($comment)){} and it works
Copy linkTweet thisAlerts:
@NightShift58Feb 22.2007 — Don't use empty(), it can lead to unexpected results, i.e. if the variable contained a "0", it would be reported as empty and unless you wanted that, it could lead to a situation that would be hard to debug.

Instead, use:[code=php]if (isset($comment) and $comment <> "") {[/code]NogDog posted an equivalent RegEx a few days ago which will deal with the issue a bit more elegantly. You may to look for that.
×

Success!

Help @Big_Jay 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.13,
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,
)...