/    Sign up×
Community /Pin to ProfileBookmark

capturing value prob

Hi guys,

I tried to send these info to my mailbox by using mail function… but i can’t get the value for the totalCost in my email.. (I can get the others)

can you guys check whats wrong with my code ??

my code:

if($_SESSION[‘mem’] == “assc”)
{
while($row = mysql_fetch_array($result))
{
$totalCost += ($row[“qty”] * $row[“associate”]);

$contents .=”Item: {$row[‘itemName’]}n”;
$contents .=”Name: {$row[‘itemDesc’]}n”;
$contents .=”Price per item: USD”;
$contents .= number_format($row[‘associate’], 2,’.’, ‘.’) . “n”;
$contents .=”Quantity: {$row[‘qty’]}n”;
}
$contents .=”Total amount: USD {$totalCost} n”;
}
elseif ($_SESSION[‘mem’] == “dist”)
{
while($row = mysql_fetch_array($result))
{
$totalCost += ($row[“qty”] * $row[“distributor”]);
$contents .=”Item: {$row[‘itemName’]}n”;
$contents .=”Name: {$row[‘itemDesc’]}n”;
$contents .=”Price per item: USD”;
$contents .= number_format($row[‘associate’], 2,’.’, ‘.’) . “n”;
$contents .=”Quantity: {$row[‘qty’]}n”;
}
$contents .=”Total amount: USD {$totalCost} n”;
}
else
{
while($row = mysql_fetch_array($result))
{
$contents .=”Item: {$row[‘itemName’]}n”;
$contents .=”Name: {$row[‘itemDesc’]}n”;
$contents .=”Price per item: USD”;
$contents .= number_format($row[‘associate’], 2,’.’, ‘.’) . “n”;
$contents .=”Quantity: {$row[‘qty’]}n”;
}
$contents .=”Total amount: USD {$totalCost} n”;
}

— mail function ()

PLease advise.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@DaiWelshDec 08.2003 — Which part of the if/else is firing, because you have not set $totalCost in the final else section.

Otherwise, it may be that one of the two values you are trying to multiply together is not defined and hence $totCost ends up undefined. Try turning up the error reporting and you will probably find the error in no time.

Incidentally the code shown does not init $totCost though PHP will let you get away with that if the errorreporting is low it is not good practice.
Copy linkTweet thisAlerts:
@AliciaauthorDec 09.2003 — Is that mean i should put $totalCost = 0 before the if - else statement ?
Copy linkTweet thisAlerts:
@DaiWelshDec 10.2003 — Assuming there is no other code refering to it above that then yes. This is always good practice but is particulalry importnat if you run on a server with register globals on otherwise I could call your script with

?totalCost=100

and suddenly your figures are coimng through 100 higher than intended !!!
×

Success!

Help @Alicia spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...