I am calculating a payment based on which country a user lives in. Any help would be muchly appreciated. It is probable a simple little error... I just cannot crack it!
The code is collecting the country variable correclty but when I do the calculations the output of print $delivery = "Countryname.1" ie "Australia.1"..
All I need it to do is output the number ".05" if the user is australian else ".1".
The code is below...Do you have any ideas.
<? $user_country = pv($country);
$au = "Australia";
$delivery = "0";
if ($user_country == "Australia")
$delivery = ".05";
else
$delivery = ".1";
print $delivery;
?>
?>
Simple if then Calculation
Moderator: General Moderators
-
billybongchong
- Forum Newbie
- Posts: 5
- Joined: Tue Nov 04, 2003 5:01 pm
- Location: Australia
-
d3ad1ysp0rk
- Forum Donator
- Posts: 1661
- Joined: Mon Oct 20, 2003 8:31 pm
- Location: Maine, USA
Code: Select all
<?PHP
$user_country = pv($country);
$au = "Australia";
$delivery = "0";
if ($user_country == "Australia")
{
$delivery = ".05";
}
else
{
$delivery = ".1";
}
echo $delivery;
?>-
billybongchong
- Forum Newbie
- Posts: 5
- Joined: Tue Nov 04, 2003 5:01 pm
- Location: Australia
I tried this... above
I tried the suggested code but am getting a parse error on line 10..
// else - this is line 10 ??
Very confusing... I think that it should work.
// else - this is line 10 ??
Very confusing... I think that it should work.
-
microthick
- Forum Regular
- Posts: 543
- Joined: Wed Sep 24, 2003 2:15 pm
- Location: Vancouver, BC
-
billybongchong
- Forum Newbie
- Posts: 5
- Joined: Tue Nov 04, 2003 5:01 pm
- Location: Australia
$user_country prints the correct information when I include it in the process page....
I tried this as well and the out put = "AustraliaYou...Australia-You Should!.1"
$user_country = pv($country);
$au = "Australia";
$delivery = "0";
if ($user_country == "Australia") {
print ("I like Australia as well");
$delivery = "0.05";
} else {
print ("You don't live in Australia - You Should!");
$delivery = ".1";
}
echo $delivery;
I tried this as well and the out put = "AustraliaYou...Australia-You Should!.1"
$user_country = pv($country);
$au = "Australia";
$delivery = "0";
if ($user_country == "Australia") {
print ("I like Australia as well");
$delivery = "0.05";
} else {
print ("You don't live in Australia - You Should!");
$delivery = ".1";
}
echo $delivery;
-
microthick
- Forum Regular
- Posts: 543
- Joined: Wed Sep 24, 2003 2:15 pm
- Location: Vancouver, BC
I still believe this line:
$user_country = pv($country);
Is the problem.
pv($country) is printing "Australia" but it is not assigning any value to $user_country. Why do I think this? Because "Australia" is appearing as the first part of the output, but you are never explicitly echoing $user_country.
So $user_country probably equals "".
To check this theory, change:
$user_country = pv($country);
to
$user_country = "Australia";
and I bet the output will be correct.
If that's the case, then you have to find an alternative to pv($country).
$user_country = pv($country);
Is the problem.
pv($country) is printing "Australia" but it is not assigning any value to $user_country. Why do I think this? Because "Australia" is appearing as the first part of the output, but you are never explicitly echoing $user_country.
So $user_country probably equals "".
To check this theory, change:
$user_country = pv($country);
to
$user_country = "Australia";
and I bet the output will be correct.
If that's the case, then you have to find an alternative to pv($country).
-
billybongchong
- Forum Newbie
- Posts: 5
- Joined: Tue Nov 04, 2003 5:01 pm
- Location: Australia
This is what I ended up with and everything works fine... Thanks guys...
<?
$Host = "localhost";
$User = "xxx";
$Pass = "xxx";
$DataBase = "xxx";
$SQL ="SELECT country FROM table WHERE username = '{$SESSION["user"]["username"]}'" ;
$Connection = mysql_connect($Host,$User,$Pass);
$SQL_Query = mysql_select_db($DataBase, $Connection);
$result = mysql_query($SQL);
$SQL_Array = mysql_fetch_array($result);
$user_country =$SQL_Array ['country'];
//echo $user_country;
// Calulate Percentage Charge for Posting
$au = "Australia";
$subtotal_cost = $SESSION["cart"]->total;
if ($user_country == $au) {
$delivery_percent = .05;
}else{
$delivery_percent = .1;
}
// Mutiplies subtotal with delivery percentage to give total delivery charges
$delivery_charge = $delivery_percent * $subtotal_cost;
?>
<?
$Host = "localhost";
$User = "xxx";
$Pass = "xxx";
$DataBase = "xxx";
$SQL ="SELECT country FROM table WHERE username = '{$SESSION["user"]["username"]}'" ;
$Connection = mysql_connect($Host,$User,$Pass);
$SQL_Query = mysql_select_db($DataBase, $Connection);
$result = mysql_query($SQL);
$SQL_Array = mysql_fetch_array($result);
$user_country =$SQL_Array ['country'];
//echo $user_country;
// Calulate Percentage Charge for Posting
$au = "Australia";
$subtotal_cost = $SESSION["cart"]->total;
if ($user_country == $au) {
$delivery_percent = .05;
}else{
$delivery_percent = .1;
}
// Mutiplies subtotal with delivery percentage to give total delivery charges
$delivery_charge = $delivery_percent * $subtotal_cost;
?>