php - Check-boxes Addition ($_POST) -



php - Check-boxes Addition ($_POST) -

i wondering how create when click 2 check-boxes submit, value appears; in case wanted value "15 percent"

i have tried create work in several ways & read '$_post' in php manual can't figure out how solve problem

php lab 04

<form name="orderform" action="<?php echo $_server['php_self'];?>" method="post"> discount<br /> <input type="checkbox" name="discount" value="student"/>customer 1 15%<br /> <input type="checkbox" name="discount" value="senior"/>customer 2 10%<br /> <input type="checkbox" name="discount" value="klant"/>customer 3 5% <br /> <input type="image" src="button.jpg" value="order" /> </form> <br /> total discount <?php if(isset($_post['discount'])) { if($_post['discount']=="student") { echo "15 percent"; } else if($_post['discount']=="senior") { echo "10 percent"; } else if($_post['discount']=="klant") { echo "5 percent"; } else if($_post['discount']=="senior" && $_post['discount']=="klant") { echo "15 percent"; } } ?> </body>

results of client 2 & client three

http://i.stack.imgur.com/qsuqu.png

you should utilize radio instead of checkbox seek following:

<form name="orderform" action="<?php echo $_server['php_self'];?>" method="post"> discount<br /> <input type="radio" name="discount" value="student"/>customer 1 15%<br /> <input type="radio" name="discount" value="senior"/>customer 2 10%<br /> <input type="radio" name="discount" value="klant"/>customer 3 5% <br /> <input type="image" src="button.jpg" value="order" /> </form>

i assume want 1 of selected @ time, not multiple.

update:

if want mentioned in comment have @5parc mentioned. here code, "although think there improve way accomplish trying do":

<form name="orderform" action="<?php echo $_server['php_self'];?>" method="post"> discount<br /> <input type="checkbox" name="discount[]" value="student"/>customer 1 15%<br /> <input type="checkbox" name="discount[]" value="senior"/>customer 2 10%<br /> <input type="checkbox" name="discount[]" value="klant"/>customer 3 5% <br /> <input type="image" src="button.jpg" value="order" /> </form> <br /> total discount <?php if(isset($_post['discount'])) { if(in_array('senior', $_post['discount']) && in_array('klant', $_post['discount'])) { echo "15 percent"; } else if(in_array('student', $_post['discount'])) { echo "15 percent"; } else if(in_array('senior', $_post['discount'])) { echo "10 percent"; } else if(in_array('klant', $_post['discount'])) { echo "5 percent"; } } ?> </body>

php

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -