checkbox question

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
zeroanarchy
Forum Newbie
Posts: 15
Joined: Wed Jul 21, 2004 8:51 pm

checkbox question

Post by zeroanarchy »

Hi, was hoping someone might be able to help me, as you can see below I have 4 checkboxes; I am trying to print out the options selected on page 2. The problem is that it prints the oposite to the onces selected. I was also wondering if there was a way of printing, "None selected" if none of the checkboxes where selected. I do not want to use an array as I have more than print planed for each selection.

Any ideas, thanks in advance.
zeroanarchy


Page1 test.php

Code: Select all

<body> 
<form name="form1" method="post" action="results.php"> 
<table width="300"  border="0" cellspacing="0" cellpadding="0"> 
  <tr> 
    <td><input type="checkbox" name="C1" value="Football"></td> 
    <td>Football</td> 
  </tr> 
  <tr> 
    <td><input type="checkbox" name="C2" value="Rugby"></td> 
    <td>Rugby</td> 
  </tr> 
  <tr> 
    <td><input type="checkbox" name="C3" value="Cricket"></td> 
    <td>Cricket</td> 
  </tr> 
  <tr> 
    <td><input type="checkbox" name="C4" value="Tennis"></td> 
    <td>Tennis</td> 
  </tr> 
</table> 
<p> 
  <input type="submit" name="Submit" value="Submit"> 
</p> 
</form> 
</body>


Page2 Results.php

Code: Select all

<?php
 //if (!isset($_POST&#1111;'sports'])) &#123;Print "You did not select any sports, you really should do some exercise!"; &#125;
 if (!isset($C1) == True)&#123;Print "Rugby was selected";&#125;
 if (!isset($C2) == True)&#123;Print "Footbal was selected";&#125;
 if (!isset($C3) == True)&#123;Print "Cricket was selected";&#125;
 if (!isset($C4) == True) &#123;Print "Tennis was selected";&#125;
?>
zeroanarchy
Forum Newbie
Posts: 15
Joined: Wed Jul 21, 2004 8:51 pm

Post by zeroanarchy »

ok it all thanks all.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

put them all the checkbox names into an array then check to see if all of the values are checked with a [php_man]foreach()[/php_man]statement.. if not do not send them to the next page..
Post Reply