dqwnxdhb88531
2016-04-28 17:52
浏览 30
已采纳

检查表单中的PHP变量[重复]

This question already has an answer here:

trying to use a php variable inside a form without much success

its just a simple check to see if a questions on the form should be asked or not

here is what I have been trying:

<?php if ($asksex = 1): ?>
Gender <br>
  <input type="radio" name="sex" value="male" checked> Male<br>
  <input type="radio" name="sex" value="female"> Female
    
    
<?php else : ?>
    
<?php endif; ?>

<?php if ($asknews = 1): ?>
    Subscribe me to your news letter
  <input type="checkbox" name="sex" value="yes" checked= true>
    
    
    <?php else : ?>
    
<?php endif; ?>

what am i doing wrong?

</div>
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongwen2162 2016-04-28 17:54
    已采纳

    You're using an assignment operator, not a comparison operator. Try -

    <?php if ($asksex == 0): ?>
    Gender <br>
      <input type="radio" name="sex" value="male" checked> Male<br>
      <input type="radio" name="sex" value="female"> Female
    
    <?php else : ?>
    
    <?php endif; ?>
    
    <?php if ($asknews == 0): ?>
        Subscribe me to your news letter
      <input type="checkbox" name="sex" value="yes" checked= true>
    
        <?php else : ?>
    
    <?php endif; ?>
    
    已采纳该答案
    打赏 评论
  • douwen5833 2016-04-28 17:54

    Try as follows

    <?php if ($asksex == 0): ?>
    Gender <br>
      <input type="radio" name="sex" value="male" checked> Male<br>
      <input type="radio" name="sex" value="female"> Female
    
    
    <?php else : ?>
    
    <?php endif; ?>
    
    <?php if ($asknews == 0): ?>
        Subscribe me to your news letter
      <input type="checkbox" name="sex" value="yes" checked= true>
    
    
        <?php else : ?>
    
    <?php endif; ?>
    
    打赏 评论

相关推荐 更多相似问题