if then state with echo

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tonyledenko
Forum Newbie
Posts: 15
Joined: Thu Sep 11, 2008 4:22 pm

if then state with echo

Post by tonyledenko »

Hello,

Below is a form redirect page. When the form is filled out the following will be seen on the redirect page. What I would like to do is hide the echos that aren't filled out.

So, for instance, if the name and company are filled out then I would like the redirect page to look like this:

Name: What ever is typed in
Company: What ever is typed in


Then I would like the other fields to be hidden.

Currently if the name and company are filled in then it looks like this:

Name: What ever is type in
Company: What ever is typed in
Phone:
Email:
Address:
City:
State:


<span class="content"><strong>Name:</strong></span> <span class="contentred"><?php echo $fullname; ?></span><br>
<span class="content"><strong>Company:</strong></span> <span class="contentred"><?php echo $company; ?></span><br>
<span class="content"><strong>Phone:</strong></span> <span class="contentred"><?php echo $phone; ?></span><br>
<span class="content"><strong>Email:</strong></span> <span class="contentred"><?php echo $email; ?></span><br>
<span class="content"><strong>Address:</strong></span> <span class="contentred"><?php echo $address; ?></span><br>
<span class="content"><strong>City:</strong></span> <span class="contentred"><?php echo $city; ?></span><br>
<span class="content"><strong>State:</strong></span> <span class="contentred"><?php echo $state; ?></span><br>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: if then state with echo

Post by requinix »

The if construct can be really helpful if you know what it is. Consider using it to print something only if a condition is true.

Code: Select all

<?php if ($fullname) echo '<span class="content"><strong>Name:</strong></span> <span class="contentred">', $fullname, '</span><br>'; ?>
tonyledenko
Forum Newbie
Posts: 15
Joined: Thu Sep 11, 2008 4:22 pm

Re: if then state with echo

Post by tonyledenko »

Thank you, your "if" statement works perfect!
Post Reply