Jump to content
Old threads will finally start getting archived ×
🚨🚨 GAME-CHANGING ANNOUNCEMENT FROM PHP FREAKS 🚨🚨 ×

Recommended Posts

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

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{}).

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.