ok so far from working wit php I come to realize that its bascially html and javascript coding together, i was never taught any of this so basically just been trying to teach myself

my question is this, I have uploaded a screenshot of something I am working on
theres option 1, 2 and 3 and then a bonus option if all three are selected

say for just theory option 1 if checked is worth 25 points
option 2 if checked is 30 points
option 3 if checked is 40 points
if all three are checked then bonus adds 75 tp op1+op2+op3

i know this is roughly just all if/else commands but not to familiar with the coding to possibly choose if two out of the three were selected to add those, if none are selected return an error, and if the bonus is selected without clicking all three return an error

any help would be much appreciated, I know this is a very basic tasks especially someone with experience in this area

Recommended Answers

All 2 Replies

Try:

<?php
if( isset($_POST['selectedBox']) && !empty($_POST['selectedBox']) )
{
  $total=0;
  foreach($_POST['selectedBox'] as $index=>$value)
  {
    echo 'Checked Item '. $index;
    $total += $value;
  }

  if( 3==count($_POST['selectedBox']) )
  {
    echo 'you get 75 bonus points for selecting all';
    $total +=75;
  }

  echo 'Your total is' . $total;
}
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">
<input type='checkbox' name='selectedBox[1]' value='25'/>
<input type='checkbox' name='selectedBox[2]' value='30'/>
<input type='checkbox' name='selectedBox[3]' value='40'/>
<input type='submit' name='Submit' value='Submit' />
</form>
Member Avatar for diafol

o

k so far from working wit php I come to realize that its bascially html and javascript coding together, i was never taught any of this so basically just been trying to teach myself

I think you've been misinformed. php and JS, while sharing similar commands, like many languages, are quite different. In addition, although you can output html with php, you can output anything with it - js/json, css, xml, html, etc etc.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.