Hi
I am trying to figure out how the information posted by a form can be used to query a MySql database. I have a form with two list boxes, both listing prices - one list box is for 'from price' the other is for 'to price' both have ten entries that have been put into an arrays $Bottom and $Top respectively. The select names being From_Price and To_Price respectively.
When selecting both 'from' and 'to' values from the list boxes, the values are passed to the next page and are referred to by variables:
echo "<center>
Your selection of properties are from $From_Price to $To_Price</center><br><br>";
This is fine and the results are as expected, however when trying to use these variables to query the database that I have built which currently contains just the one table (prices):
mysql> select * from prices;
+---------+--------+----------------------------+
| prop_no | price | description |
+---------+--------+----------------------------+
| 1 | 150000 | this is a test property 1 |
| 2 | 160000 | this is a test property 2 |
| 3 | 165000 | this is a test property 3 |
| 4 | 170000 | this is a test property 4 |
| 5 | 168000 | this is a test property 5 |
| 6 | 172000 | this is a test property 6 |
| 7 | 112000 | this is a test property 7 |
| 8 | 117000 | this is a test property 8 |
| 9 | 110000 | this is a test property 9 |
| 10 | 185000 | this is a test property 10 |
| 11 | 205000 | this is a test property 11 |
| 12 | 154000 | this is a test property 12 | ETC....
Using the following code:
...
$link_id = db_connect();
$result = mysql_query("select * from prices WHERE price >= $From_Price and price <= $To_Price order by price", $link_id);
while($query_data = mysql_fetch_row($result)) {
echo "Property no: ",$query_data[0]," is priced at £",$query_data[1]," and the description on this is: ",$query_data[2],"<BR>","<BR>";
...
I get nothing back as a result, if I replace the $From_Price and $To_Price variables with static values the query works returning only those specific values as it should, thus the connection to the database is ok.
Can anyone please advise me on how this might be possible, I have read book over and over but cannot work out how to link form values/variables with data in a MySql database.
Any help would be most appreciated.
Jamal