Jump to content

Archived

This topic is now archived and is closed to further replies.

xtiancjs

if else to display form

Recommended Posts

Hi all, I am trying to write a hopefully simple if else statement that would be something like this psuedo code

if $variable = o display <form>form content</form>
else echo"some message to the user"

not quite sure how I would write that.

xtian

Share this post


Link to post
Share on other sites
Have you tried anything yet?

Something like this should work:

[code]<?php
if ($variable == 'o') { ?>
<form ...>

</form>
<?php } else echo "some message to the user<br>\n";
?>[/code]

Ken

Share this post


Link to post
Share on other sites
[!--quoteo(post=360766:date=Apr 1 2006, 08:06 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Apr 1 2006, 08:06 PM) [snapback]360766[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Have you tried anything yet?

Something like this should work:

[code]<?php
if ($variable == 'o') { ?>
<form ...>

</form>
<?php } else echo "some message to the user<br>\n";
?>[/code]

Ken
[/quote]

Thanks for the quick reply, I have attempted a few things , I had enclosed everything in only one <?php ?>, and was having trouble with my form,thanks again ,will try it out
xtian

Share this post


Link to post
Share on other sites
[!--quoteo(post=360768:date=Apr 1 2006, 08:13 PM:name=xtiancjs)--][div class=\'quotetop\']QUOTE(xtiancjs @ Apr 1 2006, 08:13 PM) [snapback]360768[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Thanks for the quick reply, I have attempted a few things , I had enclosed everything in only one <?php ?>, and was having trouble with my form,thanks again ,will try it out
xtian
[/quote]

Hi , just intergrated your suggestion Ken, it worked like a charm, out of general interest here is the final code I used
[code]<td><?php $vipone = $_SERVER['REMOTE_ADDR'];
               $viponeq = mysql_query("SELECT ip FROM voter_ip WHERE ip = '$vipone'");
               if ($viponeq == '0') { ?>
            <form method="post" name="form1" action="<?php echo $editFormAction; ?>">
                <table align="center">
                  <tr valign="baseline">
                    <td nowrap align="right"><select name="broker_rating" onClick="DoSubmission1();">
                        <?php
do {  
?>
                        <option value="<?php echo $row_valueset['value']?>"<?php if (!(strcmp($row_valueset['value'], $row_bprofile['broker_rating']))) {echo "selected=\"selected\"";} ?>><?php echo $row_valueset['value']?></option>
                        <?php
} while ($row_valueset = mysql_fetch_assoc($valueset));
  $rows = mysql_num_rows($valueset);
  if($rows > 0) {
      mysql_data_seek($valueset, 0);
      $row_valueset = mysql_fetch_assoc($valueset);
  }
?>
                      </select></td>
                    <td></td>
                  <tr>
                </table>
                <input type="hidden" name="id" value="<?php echo $row_bprofile['id']; ?>">
                <input type="hidden" name="broker_num_votes" value="<?php echo $row_bprofile['broker_num_votes']; ?>">
                <input type="hidden" name="MM_update" value="form1">
                <input type="hidden" name="id" value="<?php echo $row_bprofile['id']; ?>">
                <input type="hidden" name="ip" value="<?php echo($_SERVER['REMOTE_ADDR']); ?>">
                <input type="hidden" name="page" value="<?php echo($_SERVER['REQUEST_URI']); ?>">
                <input type="hidden" name="MM_insert" value="form1">
              </form><?php } else echo "You have already voted!<br>\n"; ?></td>[/code]

thanks again

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.