0

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?

ian
  • 3
  • 2

2 Answers2

0

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; ?>
WillardSolutions
  • 2,316
  • 4
  • 28
  • 38
0

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; ?>
Arshid KV
  • 9,631
  • 3
  • 35
  • 36