dthomas31uk Posted October 14, 2008 Share Posted October 14, 2008 Hi. I have created a database called europe and a table called eu_place with the following fields and data ---------------------------------------------------------------------- id | country | city | full_price | half_price 1 | France | Paris | 50 | 50 2 | Spain | Barcelona | 70 | 85 Now what I am trying to do is to show a user a price based on the country selected from a drop down list, a city selected from a drop down list and then the user chooses full load price or half load price for that city and it displays the price. I have managed to get the user to choose the country and city and I get the user to chooses the full load price or half load price but I think something is not right with my SQL. This is the code that calculates the results, not sure if it is to do with the sql statement if ($load =='full_load'){ $result=mysql_query("SELECT full_price from eu_place where city = '$subcat' "); } else {$result=mysql_query("SELECT half_price from eu_place where city = '$subcat' "); } here is all the code $cat is the country $subcat is the city $load is the radio button full load or half load Hope someone can help cheers guys, its been tearing my hair out <?php include 'dd.php'; ?> <!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title>Demo Multiple drop down list box from plus2net</title> </head> <body> <?php $cat=$_POST['cat']; $subcat=$_POST['subcat']; $load=$_POST['load']; echo "Value of \$cat = $cat <br>Value of \$subcat = $subcat"."<BR>"; echo "Value of \$load = $load"; if ($load =='full_load'){ $result=mysql_query("SELECT full_price from eu_place where city = '$subcat' "); } else {$result=mysql_query("SELECT half_price from eu_place where city = '$subcat' "); } echo mysql_error(); while ($row = mysql_fetch($result)) { echo $row; } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/128327-help-getting-a-price-from-a-database/ Share on other sites More sharing options...
chris_2001 Posted October 14, 2008 Share Posted October 14, 2008 What exactly does it do? Any errors or anything? And what do you think is wrong exactly? Does the query fail or what? Link to comment https://forums.phpfreaks.com/topic/128327-help-getting-a-price-from-a-database/#findComment-664776 Share on other sites More sharing options...
dthomas31uk Posted October 14, 2008 Author Share Posted October 14, 2008 Got it workin now thanks did the following $result = mysql_query("SELECT full_price, half_price FROM eu_place WHERE city = '" . mysql_real_escape_string($subcat) . "'") or die(mysql_error()); $row = mysql_fetch_array($result); if ($load == 'full_load') { echo $row['full_price']; } else { echo $row['half_price']; } Link to comment https://forums.phpfreaks.com/topic/128327-help-getting-a-price-from-a-database/#findComment-664929 Share on other sites More sharing options...
revraz Posted October 14, 2008 Share Posted October 14, 2008 Mark as Solved please Link to comment https://forums.phpfreaks.com/topic/128327-help-getting-a-price-from-a-database/#findComment-664943 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.