/    Sign up×
Community /Pin to ProfileBookmark

if() not working…

I’ve done the exact same code, except with only 2 input fields that need checking… and it works wonders. With the script below… The first 2 work as they should, the rest don’t even allow the page to render or, on clicking Submit, it does not display the missing field.

Please help…

[code=php]
<?php
if (isset($_POST[‘submit’])) {

//form variables
$your_name = $_POST[‘your_name’] ;
$friend_name = $_POST[‘friend_email’] ;
$friend_email = $_POST[‘friend_email’] ;
$output_form = false;

//first check the form for all the fields

//if ALL empty
if(empty($your_name) && empty($friend_name) && empty($friend_email)) {
echo ‘All the fields were left empty’;
$output_form = true;
}

//if YOUR NAME empty
if(empty($your_name) && (!empty($friend_name)) && (!empty($friend_email))) {
echo ‘YOUR NAME was left empty’;
$output_form = true;
}

//if FRIENDS NAME empty
if((!empty($your_name)) && empty($friend_name) && (!empty($friend_email))) {
echo ‘YOUR FRIENDS NAME was left empty’;
$output_form = true;
}

//if FRIENDS EMAIL empty
if((!empty($your_name)) && (!empty($friend_name)) && empty($friend_email)) {
echo ‘YOUR FRIENDS EMAIL left empty’;
$output_form = true;
}

//if none empty
if((!empty($your_name)) && (!empty($friend_name)) && (!empty($friend_email))) {

/*code to be executed*/

}
else{
$output_form = true;
}

if($output_form) {

?>
FORM IN HTML
<?php
}
?>

[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@tracknutOct 13.2009 — I didn't wade thru it all, but these two lines look odd to me, depending on what your intention really was...
<i>
</i>$friend_name = $_POST['friend_email'] ;
$friend_email = $_POST['friend_email'] ;


Dave
Copy linkTweet thisAlerts:
@Hooded_VillianauthorOct 13.2009 — I didn't wade thru it all, but these two lines look odd to me, depending on what your intention really was...
<i>
</i>$friend_name = $_POST['friend_email'] ;
$friend_email = $_POST['friend_email'] ;


Dave[/QUOTE]


Oh good grief... I must have been dead tired @ 3am to miss that one!!!

[CODE]
$friend_name = $_POST['friend_name'] ;
$friend_email = $_POST['friend_email'] ;
[/CODE]

Now I can't wait to get home from work to try it. Haha...

Well spotted :-)
×

Success!

Help @Hooded_Villian 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.19,
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,
)...