Scooby-Doo Posted May 25, 2012 Share Posted May 25, 2012 I am struggling again, right do my best to explain got a dropdown with 3 selections..ie <form action="prices.php" method="post" name="prices"> <select name="dropdowns" class="selectionbox" value="options" id="selection"> <option value="ns" selected="selected">Please Select</option> <option value="selection1.php">Selection 1</option> <option value="selection2.php">Selection 2</option> <option value="selection3.php">Selection 3</option> </select> When the user clicks on the "Get Prices" button it will open prices.php....but on prices.php I want to have an include("selection1.php") or (selection2.php) etc depending on what the user selected in the drop down box. Now dont laugh at my code but I have done this but dont know how to make it just chose one at the minute it is just including both of them <?php $selection1 = isset($_POST['selection1']) ? $_POST["selection1"] : ""; $selection2 = isset($_POST['selection2']) ? $_POST["selection2"] : ""; if ($selection1); include ("selection1.php"); if ($selection2); include ("selection2.php"); ?> Any help much appreciated...and as you can probably see im new to php Quote Link to comment Share on other sites More sharing options...
Drummin Posted May 25, 2012 Share Posted May 25, 2012 Not sure if this will help. <html> <body> <?php isset($_POST['dropdowns']) ? include($_POST["dropdowns"]) : ""; ?> <form action="prices.php" method="post" name="prices"> <select name="dropdowns" class="selectionbox" value="options" id="selection"> <option value="ns" selected="selected">Please Select</option> <option value="selection1.php">Selection 1</option> <option value="selection2.php">Selection 2</option> <option value="selection3.php">Selection 3</option> </select> <input type="submit" value="Submit" /> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
Psycho Posted May 25, 2012 Share Posted May 25, 2012 Sorry, but I have to advise against using Drummin's solution. You should never use values from user submitted data directly in an include statement. You need to validate it first. $includeValue = isset($_POST['dropdowns']) ? $_POST['dropdowns'] : false; switch($includeValue) { case 'selection1.php': case 'selection2.php': case 'selection3.php': include($includeValue); break; default: include('selection1.php'); } Quote Link to comment Share on other sites More sharing options...
Scooby-Doo Posted May 25, 2012 Author Share Posted May 25, 2012 Thank you Psycho worked a treat....Just one more question, I have used your code so it includes() the selected pages..ie $inspection = isset($_POST['inspections']) ? $_POST['inspections'] : false; $delivery = isset($_POST['delivery']) ? $_POST['delivery'] : false; switch($inspection) { case 'basic.php': case 'platinum.php': case 'accident.php': include($inspection); break; default: include('basic.php'); } ?> <?php switch($delivery) { case 'delivery.php': case 'nodelivery.php': include($delivery); break; default: include('nodelivery.php'); } ?> Would it be difficult to put a value to each selection...for arguments sake if someone selected Platinum Inspection £10 with no delivery £0 it would calculate the two prices and place in a total inspection + delivery Hope that makes sense Quote Link to comment 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.