anth0ny Posted January 7, 2009 Share Posted January 7, 2009 Hi all, I have a search form where if a option is selected say 'holidaybreaks' it runs a specified bit of php if($_POST['holidaybreaks']){ It isnt working and i was hoping someone could tell me why? This is the form: <select name="pricerange" class="field"> <option selected="selected">-- please select --</option> <option value="holidaybreaks">Holiday Breaks</option> <option value="cruises">Cruises</option> <option value="citybreaks">City Breaks</option> <option value="sporting">Sporting Holidays</option> <option value="flights">Flights</option> <option value="hotel">Hotel Bookings</option> </select><br /> <span class="search-subhed">Destination?</span><br /> <input name="where" type="text" value="" class="field" /><br /> <span class="search-subhed">Price?</span><br /> <select name="pricerange" class="field"> <option selected="selected">Any price</option> <option value="0:500">£0-£500</option> <option value="501:1000">£501-£1000</option> <option value="1001:2000">£1001-£2000</option> <option value="2000:10000">Over £2000</option> </select><br /> <span class="search-subhed">Duration?</span><br /> <select name="stay" class="field"> <option selected="selected">Any duration</option> <option value="1">1 night</option> <option value="2">2 nights</option> <option value="3">3 nights</option> <option value="4">4 nights</option> <option value="5">5 nights</option> <option value="6">6 nights</option> <option value="7">7 nights</option> <option value="8">8 nights</option> <option value="9">9 nights</option> <option value="10">10 nights</option> <option value="12">12 nights</option> <option value="14">14 nights</option> <option value="21">21 nights</option> </select><br /> <input name="search" type="submit" id="search" value="Search" /> </form> And this is the bit of php i want to run if holidaybreaks is selected if($_POST['holidaybreaks']){ list($min,$max) = explode(':',$_POST['pricerange'],2); $result = mysql_query("SELECT departureDate, expireDate, airport, destination, resort, hotel, duration, board, price, description, customerRef, mystiqueRef, stars FROM holiday WHERE destination LIKE '%$where%' AND duration LIKE '%$stay%' AND price BETWEEN '$min' AND '$max'"); while($r=mysql_fetch_array($result)) { $airport=$r["airport"]; $destination=$r["destination"]; $resort=$r["resort"]; $hotel=$r["hotel"]; $duration=$r["duration"]; $price=$r["price"]; $departureDate=$r["departureDate"]; $description=$r["description"]; $customerRef=$r["customerRef"]; $mystiqueRef=$r["mystiqueRef"]; $stars=$r["stars"]; $expireDate=$r["expireDate"]; $board=$r["board"]; echo " <h3 class=\"hol-subhed\">$destination</h3> <div id=\"hol-wrapper\"> <div class=\"holiday-hedlistwrap\"> <ul class=\"hol-hedlist\"> <li class=\"long\">Destination</li> <li class=\"med\">Airport</li> <li class=\"long\">Resort</li> <li class=\"long\">Hotel</li> <li class=\"med\">Board</li> <li class=\"med\">Duration</li> <li class=\"med\">Depart On</li> <li class=\"small\">Price</li> </ul> </div> <div class=\"holiday-detailswrap\"> <ul class=\"hol-details\"> <li class=\"long\">$destination</li> <li class=\"med\">$airport</li> <li class=\"long\">$resort</li> <li class=\"long\">$hotel</li> <li class=\"med\">$board</li> <li class=\"med\">$duration</li> <li class=\"med\">$departureDate</li> <li class=\"small\">£$price</li> </ul> <div class=\"clearboth\" id=\"foo\"><!--empty--></div> </div> <div class=\"holiday-descwrap\"> <ul class=\"hol-hedlist\"> <li class=\"huge\">Description</li> <li class=\"med\">Rating</li> <li class=\"med\">Ref. No.</li> </ul> </div> <div class=\"holiday-detailswrap\"> <ul class=\"hol-details\"> <li class=\"huge\">$description</li> <li class=\"med\"> $stars</li> <li class=\"ref\">$customerRef</li> </ul> <div class=\"clearboth\" id=\"foo\"><!--empty--></div> </div> <div class=\"holiday-descwrap\"> <ul class=\"hol-hedlist\"> <li class=\"huge\">Operator Ref</li> <li class=\"med\"></li> <li class=\"med\"></li> </ul> </div> <div class=\"holiday-detailswrap\"> <ul class=\"hol-details\"> <li class=\"huge\">$mystiqueRef</li> <li class=\"med\"></li> <li class=\"ref\"></li> </ul> <!--hol-footer--> <div class=\"clearboth\" id=\"foo\"><!--empty--></div> </div>"; } Link to comment https://forums.phpfreaks.com/topic/139843-solved-post-web-form/ Share on other sites More sharing options...
Boo-urns Posted January 7, 2009 Share Posted January 7, 2009 Hi anthOny, Are you wanting to run the code when the user selects the dropdown or after you are submitting? If its before submitting you will need to use javascript or ajax. If it's after you have a few things mixed up. First make sure that you have the beginning form tag if its not there yet. Second you have two fields with the same name. (pricerange) So change the first to something different. In the code below i used 'breakType' <?php if(isset($_POST['search'])) { //submit button clicked. $breakType = $_POST['breakType']; //changed the first dropdown name to breakType if($breakType == 'holidaybreaks') { // run your code } } // end of submitting ?> Hope this helps -Corey Link to comment https://forums.phpfreaks.com/topic/139843-solved-post-web-form/#findComment-731590 Share on other sites More sharing options...
anth0ny Posted January 7, 2009 Author Share Posted January 7, 2009 cheers Corey works great thanks! Link to comment https://forums.phpfreaks.com/topic/139843-solved-post-web-form/#findComment-731605 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.