bionic25 Posted August 15, 2008 Share Posted August 15, 2008 I'm having difficulties creating a self-containing .php page which has drop downs for price ranges eg £0 < £1000, £1000 < £2000 etc. I then want it to query a mysql database called "cars" and field "price" and then display the results. code so far: <form action=\"<?php $_SERVER['PHP_SELF'] ?>\" method=\"post\"> Lowest price:<input type=\"text\" name=\"low\"> Highest price:<input type=\"text" name=\"high\"> <input type=\"submit\" value=\"submit\" action=\"submit\"> </form> <?php if (isset($_POST['Submit'])) { mysql_connect("***", "***", "***") or die(mysql_error()); mysql_select_db("***") or die(mysql_error()); $low = $_POST['low']; $high = $_POST['high']; $result = mysql_query("select * from cars WHERE price BETWEEN $low and $high"); while($r=mysql_fetch_array($result)) { $carName=$r["carName"]; $description=$r["description"]; echo " $carName $description "; } } else { echo" <form action=\"<?php $_SERVER['PHP_SELF'] ?>\" method=\"post\"> <input type=\"text\" name=\"low\">Lowest price: <input type=\"text" name=\"high\">Highest price: <input type=\"submit\" value=\"submit\" action=\"submit\"> </form> "; ?> This just doesn't work at all. Anyone know where I'm going wrong? (this is one of the first scripts I've written from scratch) Thanks, ~bionic25 Link to comment https://forums.phpfreaks.com/topic/119864-minmax-price-range-query/ Share on other sites More sharing options...
akitchin Posted August 15, 2008 Share Posted August 15, 2008 i BELIEVE that variables are case-sensitive. try changing $_POST['Submit'] to $_POST['submit']. i would also be wary of letting the users input the price range - as you said, you'd be better off using a select dropdown list. i'm also not sure why you echo the form twice (once at the start and once in the else{}). Link to comment https://forums.phpfreaks.com/topic/119864-minmax-price-range-query/#findComment-617493 Share on other sites More sharing options...
bionic25 Posted August 15, 2008 Author Share Posted August 15, 2008 Thanks for reply. I changed the case but still no luck... By the way that form double up was just a copy/paste typo Any other ideas? It's not outputting anything, not even the form?!?! Link to comment https://forums.phpfreaks.com/topic/119864-minmax-price-range-query/#findComment-617497 Share on other sites More sharing options...
akitchin Posted August 15, 2008 Share Posted August 15, 2008 it'll be in the $_SERVER['PHP_SELF'] - you're missing both an echo and a semicolon to end the line. when nothing shows on a page, it's usually because of a parse error that's not being output. plug this into the top of your file (before editing the $_SERVER part): <?php ini_set('display_errors', 'On'); error_reporting(E_ALL); ?> and you'll suddenly see some notifications of where the script is going astray. Link to comment https://forums.phpfreaks.com/topic/119864-minmax-price-range-query/#findComment-617514 Share on other sites More sharing options...
dbo Posted August 15, 2008 Share Posted August 15, 2008 We need more information than "this doesn't work." Is it a logic or a syntax error? Assuming it is a logic error... did you try this? $query = "select * from cars WHERE price > $low and price < $high"; Link to comment https://forums.phpfreaks.com/topic/119864-minmax-price-range-query/#findComment-617521 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.