decypher Posted July 18, 2007 Share Posted July 18, 2007 Hey again...same problem as last time kinda but with checkboxes Html: <html> <head> <title>Checkboxes</title> </head> <body> <h1>Checkbox Demo</h1> <h3>Demonstrates checkboxes</h3> <form action ="checkdemo.php"> <h3>What would you like with your order?</h3> <ul> <li><input type ="checkbox" name ="chkfries" value ="1.00">Fries </li> <li><input type ="checkbox" name ="chksoda" value =".85">Soda </li> <li><input type ="checkbox" name ="chkshake" value ="1.30">Shake </li> <li><input type ="checkbox" name ="chkketchup" value =".05">Ketchup </li> </ul> <input type = "Submit" value = "Order"> </form> </body> </html> php: <html> <head> <title>Checkbox Demo</title> </head> <body> <h3>Demonstrates reading checkboxes</h3> <?php $chkfries = $_POST['chkfries']; $chksoda = $_POST['chksoda']; $chkshake = $_POST['chkshake']; $chkketchup = $_POST['chkketchup']; print <<<HERE ChkFries: $chkfries <br> ChkSoda: $chksoda <br> ChkShake: $chkshake <br> ChkKethcup: $chkketchup <br> <hr> HERE; $total = 0; if (!empty($chkfries)){ print ("You chose Fries <br> \n"); $total = £total + $chkfries; } // end if if (!empty($chksoda)){ print ("You chose Soda <br> \n"); $total = £total + $chksoda; } // end if if (!empty($chkshake)){ print ("You chose Shake <br> \n"); $total = £total + $chkshake; } // end if if (!empty($chkketchup)){ print ("You chose Ketchup <br> \n"); $total = £total + $chkketchup; } // end if print "The total cost is \$$total \n"; ?> </body> </html> Sorry for the inconvenience... Quote Link to comment https://forums.phpfreaks.com/topic/60656-solved-checkbox-problem/ Share on other sites More sharing options...
Daniel0 Posted July 18, 2007 Share Posted July 18, 2007 What was your "last problem"? Also, you're using £total instead of $total. It might also be better to store the price in the script so people don't change it before submitting. Quote Link to comment https://forums.phpfreaks.com/topic/60656-solved-checkbox-problem/#findComment-301768 Share on other sites More sharing options...
decypher Posted July 18, 2007 Author Share Posted July 18, 2007 my last proble was firstly: Code: <html> <head> <title>Font Choices</title> </head> <body> <center> <h1>Font Choices</h1> <h3>Demonstrates how to read HTML form elements</h3> <form method = "post" action = "bordermaker.php"> <h3>Text to modify</h3> <textarea name= "basictext" rows= "10" cols= "40"> Woohoo I'm acutally making a textarea. I have also been able to make different kind of borders, with diferent fonts and sizes. How good am I? I bet you're really impressed aren't you.So ner ner ner ner! </textarea> <Table border = 2> <tr> <td><h3>Border style</h3></td> <td colspan = 2><h3>Border Size</h3></td> </tr> <tr> <td> <Select name = Borderstyle> <option vale = "ridge">Ridge</option> <option vale = "groove">Groove</option> <option vale = "double">Double</option> <option vale = "inset">Inset</option> <option vale = "outset">Outset</option> </select> </td> <td> <Select size = 5 name = Bordersize> <option vale = "1">1</option> <option vale = "2">2</option> <option vale = "3">3</option> <option vale = "5">5</option> <option vale = "10">10</option> </select> </td> <td> <input type = "radio" name = "sizetype" value = "px">pixels<br> <input type = "radio" name = "sizetype" value = "pt">points<br> <input type = "radio" name = "sizetype" value = "cm">centimeters<br> <input type = "radio" name = "sizetype" value = "in">inches<br> </td> </tr> </table> </table> <input type = "Submit" value = "Show me"> </center> </body> </html> then... Code: <Html> <Head> <Title>Your output</title> </head> <body> <h1>Your Output</h1> <Center> <?php $theStyle = <<<HERE "border-width:$Bordersize$sizetype; border-style:$Borderstyle; border-color:Red" HERE; print "<div style = $theStyle>"; print $basictext; print "</span>"; ?> </center> </body> </html> but that was fixed using the $theStyle = $_POST['theStyle']; coding for all variables However, won't work this time round while using checkboxes...I'm only a beginner Quote Link to comment https://forums.phpfreaks.com/topic/60656-solved-checkbox-problem/#findComment-301779 Share on other sites More sharing options...
Daniel0 Posted July 18, 2007 Share Posted July 18, 2007 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Checkboxes</title> </head> <body> <h1>Checkbox Demo</h1> <h2>Demonstrates checkboxes</h2> <form action='test.php' method='post'> <h3>What would you like with your order?</h3> <ul> <li><label><input type="checkbox" name="fries" value="1" /> Fries</label></li> <li><label><input type="checkbox" name="soda" value="1" /> Soda</label></li> <li><label><input type="checkbox" name="shake" value="1" /> Shake</label></li> <li><label><input type="checkbox" name="ketchup" value="1" /> Ketchup</label></li> </ul> <input type="submit" value="Order" /> </form> </body> </html> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Checkboxe Demo</title> </head> <body> <h2>Demonstrates reading checkboxes</h2> <?php $items = array( 'fries' => 1, 'soda' => .85, 'shake' => 1.3, 'ketchup' => .05, ); $list1 = null; $list2 = null; $total = 0; foreach($items as $name => $price) { $state = $_POST[$name]=='1' ? true : false; $list1 .= "{$name}: "; $list1 .= $state ? "yes" : "no"; $list1 .= "<br />"; if($state == true) { $list2 .= "You ordered '{$name}'<br />"; $total += $price; } } $total = number_format($total,2); echo <<<EOF {$list1} <hr /> {$list2}<br /> Your total price is: \${$total} EOF; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/60656-solved-checkbox-problem/#findComment-301811 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.