Gossamer Forum
Home : Products : DBMan : Customization :

Need a little help with if statement

Quote Reply
Need a little help with if statement
I have a checkbox that users can check when they add a record to whether they want to display their private information (i.e. email address and phone number) or if they check the box, they want to use the private mailer mod I have setup.

So I have this code, but its not working:

if ($rec{'Pmailer'}) {
print qq|
<TR><TD colspan=2><$font_color>
This user has preferred for all contacts to use our private mailer option.<p>
Click <a href="$db_script_link_url&$db_key=$rec{$db_key}&send_email_form=1">here</a>&nbsp;to contact this user.
else {
print qq|
<TR><TD width="200"><$font_color>Email:</FONT></TD>
<TD align="right">&nbsp;<$font>$rec{'Email2'}</font><p></TD></TR>

<TR><TD width="200"><$font_color>Phone:</FONT></TD>
<TD align="right">&nbsp;<$font>$rec{'Phone2'}</Font><p></TD></TR>

Ive also tried the if ($rec{'Pmailer'} eg "Yes") and if ($rec{'Pmailer'} == 1), but neither of those worked either. Right now, as I have it above, it is showing the private mailer link no matter if the user checks the box or not. Can someone give me a little direction as to the right code?
Quote Reply
Re: [wdu2002] Need a little help with if statement In reply to
the first option
if ($rec{'fieldname'})
basically says if the field is not empty, then do something - so it'd print whether value was yes or no.

On the second option - check your syntax.. should be
if ($rec{'fieldname'} eq "Yes"){then do something}
not sure if that was a typo or not

Third option try
if ($rec{'fieldname'} == "1"){then do something}

Make sure you are setting your check box value accordingly (Yes, 1, etc)

Otherwise it looks like it *should* work. Check the db to see if there is a value being set for that field (ie, does the checkbox work at all?)
Quote Reply
Re: [Watts] Need a little help with if statement In reply to
Thanks Watts....I realized what I did was left the actual field value blank instead of setting it to Yes, but it works now. I guess I didnt realize where the Yes or 1 was supposed to come from. Thanks again!