Jump to content

Help getting a price from a database


dthomas31uk

Recommended Posts

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
Share on other sites

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
Share on other sites

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.