<form action="p2.php" method="POST"> <?php $sum = 0; if($_POST['category']=="hunt") { echo "Принадлежности для охоты<br>"; echo "<input type='checkbox' name='h1'> Охотничье Ружьё - 9000р<br/>"; echo "<input type='checkbox' name='h2'> Капкан - 1500р<br/>"; echo "<input type='checkbox' name='h3'> Охотничий лук - 3000р<br/>"; } if($_POST['category']=="fish") { echo "Принадлежности для рыбалки<br>"; echo "<input type='checkbox' name='f1'> Удочка - 1000р<br/>"; echo "<input type='checkbox' name='f2'> Спиннинг - 3000р<br/>"; echo "<input type='checkbox' name='f3'> Набор наживок - 350р<br/>"; } if($_POST['category']=="games") { echo "Принадлежности для компьютерных игр<br>"; echo "<input type='checkbox' name='g1'> Геймпад 2000р<br/>"; echo "<input type='checkbox' name='g2'> Игровая клавиатура 3500р<br/>"; echo "<input type='checkbox' name='g3'> Игровая мышь 2500р<br/>"; } echo "<input type='submit' name='sub' value='Выбрать'><br>"; ?> 

And here, on what refers.

  <?php $sum = 0; if($_POST['h1']=="on") { $sum+=9000; } if($_POST['h2']=="on") { $sum+=1500; } if($_POST['h3']=="on") { $sum+=3000; } if($_POST['f4']=="on") { $sum+=1000; } if($_POST['f5']=="on") { $sum+=3000; } if($_POST['f6']=="on") { $sum+=350; } if($_POST['g7']=="on") { $sum+=2000; } if($_POST['g8']=="on") { $sum+=3500; } if($_POST['g9']=="on") { $sum+=2500; } { echo "Общая стоимость снаряжения: ".$sum." рублей. <br/><br/>"; } ?> 

At the exit, I get the sum of only the first three accessories, i.e. h1, h2, h3. What have I done wrong?

    1 answer 1

    And why f4 f5 f6 g7 g8 g9? Parameters do not match, more precisely, the post array indices

    • And echo cannot be avoided by echo "<input> <br> <input> <br>"; - 5grrthrthrh 2:22 pm
    • You have in the first file f1 f2 f3 g1 g2 g3. And in the second, for some reason, f4 f5 f6 g7 g8 g9 - Diman2000zver
    • Oops. Something went wrong. Everything, now everything works. After 5 minutes, the answer I will note - Alex Flow