...

View Full Version : URGENT! Sessions not displaying correct price / coupon code on order receipt page! ><



ShadowIce
01-16-2010, 07:30 PM
I am in need of some URGENT help! Why can't I get the session to display the correct price on vieworder.php?! ><

Orderform.php:


<?php
session_start();
?><?php
/*This code is for use on www.imageposeidon.com ONLY!
Using this code without written permission from imageposeidon.com is a violation of the GNU Public License (GPL)
And will be dealt with to the fullest extent of the law
*/
?><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Image Poseidon</title>
</head>
<body onsubmit="return validate_required(this)" style="font-family: Arial">

<script src="cstate_0001.js"></script>

<?php
require('header.php');
?>

<Script Language="JavaScript" type="JavaScript">

function validate_required(field)
{

var alerttxt = "One or more fields are empty.\\nPlease fill them out before submitting";


with (field)
{

if (value==null||value=="")
{
alert(alerttxt);
return false;
}else{
return true;
}
}
}
</Script>

<FORM onsubmit="return validate_required(this)" ACTION="page2.php" method=post>

<center>
<table border="0">
<tr>
<td><label for="fname_0001">First Name: </label></td>
<td><input type="text" name="f_name0001" maxlength="30" id="f_name0001" size="30" /></td>
</tr>
<tr>
<td><label for="lname_0001">Last Name: </label></td>
<td><input type="text" name="l_name0001" maxlength="30" id="l_name0001" size="30" /></td>
</tr>
<tr>
<td><label for="a_d0001">Shipping Address: </label></td>
<td><input type="text" name="ad_0001" maxlength="128" id="ad_0001" size="30" /></td>
</tr>
<tr>
<td>Country: </td>
<td><select id='countrySelect' name='co_0001' onchange='populateState()' style="width: 209px;"></select></td>
</tr>
<tr>
<td><label for="c0001">City: </label></td>
<td><input type="text" name="c_0001" maxlength="30" id="c_0001" size="30" /></td>
</tr>
<br><br>
<tr>
<td>State: </td>
<td><select name='sp_0001' id='stateSelect' name='state' style="width: 209px;"></select></td>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
<td width=150>Item: <br>
&nbsp;</td>
<td width=15>Quantity: <br>
&nbsp;</td>
</tr>
<tr>
<td>CD</td>
<td><input type="text" name="qtycd_0001" value = "1" size="30" maxlength="7"></td>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
<tr>
<td>Please enter a discount code if you have one: </td>
<td><input type="text" name="sd_0001" value="000-000-00000" size="30" maxlength="64"></td>
</tr>
<tr>
<td><input onsubmit="return validate_required(this)" type="submit" value="Go To Next Page"></td>
</tr>

<script type="text/javascript">initCountry('US');</script>

</table>
</center>

</form>

</body>
</html>

page2.php (displays your total amount of products u bought.. etc..):


<?php
session_start();
require('sessionvars.php');
?><?php
/*This code is for use on www.imageposeidon.com ONLY!
Using this code without written permission from imageposeidon.com is a violation of the GNU Public License (GPL)
And will be dealt with to the fullest extent of the law
*/?><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Image Poseidon</title>
</head>

<body style="font-family: Arial">

<script src="view_printable.js"></script>
<script src="mainscripts.js"></script>

<center>
<a href="#" onclick="javascript:view_printable();">Click For Printable Page</a><br>
</center>

<?php
require('header.php');
require('taxheader.php');
require('sessvars.php');
?>

<center>
<h2>This is your order so far: </h2>
</center>

<FORM name="f0001" id="f0001" ACTION="processorder.php?fname=<?php echo $fname;?>" method=post>

<center>
<?php
echo "Name: <b><u>".$fname." ".$lname."</u></b><br>\n"
."Address: <b><u>".$address."</u></b><br>\n"
."Country: <b><u>".$country."</u></b><br>\n"
."City: <b><u>".$city."</u></b><br>\n"
."State/Province: <b><u>".$stateprov."</u></b><br>\n"
."Amount of CD(s) you want to purchase: <b><u>".$quantity."</u></b><br>\n";

if($hasdiscount == true){echo "Your coupon code: <b><u>".$myCoupon."</u></b><br><br>\n";}
echo "<img src=\"gradient_grey3596386127_footer-iaza.png\"></img><br>\n";

if($hasdiscount == true){

echo "<br>Original Total: <br><br>\n"
."<b>".$print_pur_po_total."-"."10%"."</b>"."<br>\n"
."<br>Your total: <br><br>\n"
."<b>".$print_pur_po_total2."</b><br>\n";

}else if($hasdiscount == false){

echo "<br>Your Total: <br><br>\n"
."<b>".$print_pur_po_total."</b><br>\n";

}

echo "<br>\n";

echo "<img src=\"gradient_grey3596386127-iaza.png\"></img>\n";

?>

<br>

<a href="#" onclick="javascript:view_printable();">Click For Printable Page</a><br><br>

<input name="subt1" id="subt1" type="submit" value="Submit" onclick="FormControl(1);">

</center>

</form>

</body>

</html>

variables.php:


<?php
$number = $Total;
$number2 = $DiscountTotal;
$pur_item_total = $number;
$pur_po_total = ($pur_po_total + $pur_item_total);
$print_pur_po_total = wims_currency($pur_po_total);
$pur_item_total2 = $number2;
$pur_po_total2 = ($pur_po_total2 + $pur_item_total2);
$print_pur_po_total2 = wims_currency2($pur_po_total2);
?>

sessionvars.php:


<?php

$_SESSION['f_name0001'] = $_POST['f_name0001'];
$_SESSION['l_name0001'] = $_POST['l_name0001'];
$_SESSION['ad_0001'] = $_POST['ad_0001'];
$_SESSION['co_0001'] = $_POST['co_0001'];
$_SESSION['c_0001'] = $_POST['c_0001'];
$_SESSION['sp_0001'] = $_POST['sp_0001'];
$_SESSION['qtycd_0001'] = $_POST['qtycd_0001'];
$_SESSION['hascouponcode'] = $myCoupon;
$_SESSION['hasadiscount'] = $hasdiscount;
$_SESSION['istotal'] = $print_pur_po_total;
$_SESSION['isdiscounttotal'] = $print_pur_po_total2;

?>

sessvars.php (different from sessionvars.php):


<?php
$fname = $_SESSION['f_name0001'];
$lname = $_SESSION['l_name0001'];
$address = $_SESSION['ad_0001'];
$country = $_SESSION['co_0001'];
$city = $_SESSION['c_0001'];
$stateprov = $_SESSION['sp_0001'];
$quantity = $_SESSION['qtycd_0001'];
$istotal = $_SESSION['istotal'];
$isdiscounttotal = $_SESSION['isdiscounttotal'];

//$hascouponcode
//$hasthediscount

// if found return the position in the array as $key
if(($key = array_search($myCoupon, $coupons)) !== false) {
$hasdiscount = true;
}
else if(($key = array_search($myCoupon, $coupons)) == false) {
$hasdiscount = false;
}
$couponcode = $myCoupon;
?>

taxheader.php:


<?php

$itemprice = 12;
$taxrate = 7;
$shipping = 1.75;
$discountrate = .90;
$qtycd = $_POST['qtycd_0001'];
$sdiscount = $_POST['sd_0001'];
$Subtotal = $itemprice;
$Tax = round( ($itemprice * $taxrate / 100 ), 2);
$Total = (($Tax + $Subtotal)*$qtycd)+($shipping*$qtycd);
$DiscountTotal = $Total*$discountrate; //round($Total*($discountrate), 2);
$coupons = file('Vm1wS01HRXhVWGxWYmxKV1lrZG9VRlpyVmt0WGJGSllZM3BHVG1KSFVubFhhMXByWWtkR05sSnJXbFpXYldoeVZrZDRWMD VzV2xsYVIwWlhWakpvVkZaVldrWlBWa0pTVUZRd1BRPT0=.txt', FILE_SKIP_EMPTY_LINES);
$coupons = array_map('trim', $coupons);
$myCoupon = $_POST['sd_0001'];
$sdiscount = $myCoupon;

// if found return the position in the array as $key
if(($key = array_search($myCoupon, $coupons)) !== false) {
$hasdiscount = true;
// delete the coupon from the array using $key
unset($coupons[$key]);
file_put_contents('Vm1wS01HRXhVWGxWYmxKV1lrZG9VRlpyVmt0WGJGSllZM3BHVG1KSFVubFhhMXByWWtkR05sSnJXbFpXY ldoeVZrZDRWMDVzV2xsYVIwWlhWakpvVkZaVldrWlBWa0pTVUZRd1BRPT0=.txt', implode("\r\n", $coupons));
}
else if(($key = array_search($myCoupon, $coupons)) == false) {
$hasdiscount = false;
}

$number = $Total;
$pur_item_total = $number;
$pur_po_total = ($pur_po_total + $pur_item_total);
$print_pur_po_total = wims_currency($pur_po_total);
$number2 = $DiscountTotal;
$pur_item_total2 = $number2;
$pur_po_total2 = ($pur_po_total2 + $pur_item_total2);
$print_pur_po_total2 = wims_currency2($pur_po_total2);

function wims_currency($number) {
if ($number < 0) {
$print_number = "($" . str_replace('-', '', number_format ($number, 2, ".", ",")) . ")";
} else {
$print_number = "$" . number_format ($number, 2, ".", ",") ;
}
return $print_number;
}

function wims_currency2($number2) {
if ($number2 < 0) {
$print_number2 = "($" . str_replace('-', '', number_format ($number2, 2, ".", ",")) . ")";
} else {
$print_number2 = "$" . number_format ($number2, 2, ".", ",") ;
}
return $print_number2;
}

?>

vieworder.php:


<?php
session_start();
?><html>
<head><title>Image Poseidon - Order Form</title></head>
<body>
<?php
require('taxheader.php');
require('variables.php');
require('sessvars.php');
?>

<center>

<h2>Your Receipt: </h2>

<?php
echo "fname: ".$fname."<br>\n"
."lname: ".$lname."<br>\n"
."address: ".$address."<br>\n"
."country: ".$country."<br>\n"
."city: ".$city."<br>\n"
."stateprov: ".$stateprov."<br>\n"
."quantity: ".$quantity."<br>\n"
."total: ".$istotal."<br>\n"
."discount total: ".$isdiscounttotal."<br>\n"
."coupon code: ".$hascouponcode."<br>\n"
."has discount: ".$hasthediscount."<br>\n";

echo "Name: <b><u>".$fname." ".$lname."</u></b><br>\n"
."Address: <b><u>".$address."</u></b><br>\n"
."Country: <b><u>".$country."</u></b><br>\n"
."City: <b><u>".$city."</u></b><br>\n"
."State/Province: <b><u>".$stateprov."</u></b><br>\n"
."Amount of CD(s) you want to purchase: <b><u>".$quantity."</u></b><br>\n";

if($hasdiscount == true){echo "Your coupon code: <b><u>".$couponcode."</u></b><br><br>\n";}

if($hasdiscount == true){

echo "<br>Original Total: <br><br>\n"
."<b>".$total."-"."10%"."</b>"."<br>\n"
."<br>Your total: <br><br>\n"
."<b>".$discounttotal."</b><br>\n";

}else if($hasdiscount == false){

echo "<br>Your Total: <br><br>\n"
."<b>".$total."</b><br>\n";

}

echo "<br>\n";

?>

</center>

<?php
function test() {
$foo = "local variable";

echo '$foo in global scope: ' . $GLOBALS["foo"] . "<br>\r\n";
echo '$foo in current scope: ' . $foo . "<br>\r\n";
}

$foo = "Example content";
test();
?>

<form name="test" id="test" action="./vartest.php" method="POST">

<input type="submit" value="Submit">

</form>

</body>
</html>

In vieworder.php, I cant get $hasdiscount to work, and I can't get $total, $discounttotal, and $myCoupon to display....

Thanks!

ShadowIce~

masterofollies
01-16-2010, 08:09 PM
There is no need to have two if's for the same thing.


if($hasdiscount == true){echo "Your coupon code: <b><u>".$couponcode."</u></b><br><br>\n";}

if($hasdiscount == true){

echo "<br>Original Total: <br><br>\n"
."<b>".$total."-"."10%"."</b>"."<br>\n"
."<br>Your total: <br><br>\n"
."<b>".$discounttotal."</b><br>\n";

}

Just to let you know, it'd clean up your code a little.

ShadowIce
01-16-2010, 08:16 PM
Thanks, but that doesn't solve this problem..

masterofollies
01-16-2010, 08:46 PM
I wasn't solving the problem, was just helping you clean the coding.

sir.jones
01-16-2010, 09:31 PM
You not just only need to solve your present code but you most need how to secure (prevent from attacker) your business membership... by looking to your present code it's seem easy for someone to delete your all membership... and also you coupon code, from the beginning when you request some helps i know you will face this problem...:D you can believe it or not

You need someone to help you out...

tomws
01-16-2010, 11:50 PM
You may be breaking it on page2. At the top, you include sessionvars.php which has these lines at the end:

$_SESSION['hascouponcode'] = $myCoupon;
$_SESSION['hasadiscount'] = $hasdiscount;
$_SESSION['istotal'] = $print_pur_po_total;
$_SESSION['isdiscounttotal'] = $print_pur_po_total2;
Those four variable on the right are undefined at that point, which means that you're assigning empty values to those session variables. I also notice that shortly after that your re-use some of them in sessvars.php and that's going to perpetuate the problem. Take a look at your session on that page with a print_r at the bottom.

A simple debug step is to echo/print/dump variables throughout a page or multiple pages to make sure you're actually getting what you think you should be getting. If I'm right with the assessment above, you would have noticed this with a simple echo.

Also, you should take the advice already offered. That code needs a bit of help.

Finally, are you imageposeidon.com? Allow me, without knowing if you're responsible, to call BS on that "license" statement at the top of those files. That's not how the GPL works. If you have put that nonsense in your files, you need to remove it before you take a beatdown for mis-using the GPL. If you're just copying-and-pasting someone else's work, I suggest learning a bit about the GPL first and then passing a friendly link (http://www.gnu.org/licenses/gpl-howto.html) back to the originator.

ShadowIce
01-16-2010, 11:52 PM
Um. EXCUSE me? I DID write that code. Why do u think its not very organized? oO
Also, go ahead. look on the internet for it. You WON'T find it.

tomws
01-17-2010, 12:00 AM
Then you need to learn to use the GPL before posting that nonsensical "license" statement at the top. If you don't want anyone to use your code, GPL is not the license you want.

ShadowIce
01-17-2010, 12:01 AM
Then what license DO I want? Cuz no one TAUGHT me where to find it

tomws
01-17-2010, 12:22 AM
It's not a world of handouts, for the most part. Some things (most?) need to be learned without being spoon-fed from a teacher.

If you're a US citizen, I suggest looking at the government's copyright site (http://www.copyright.gov) and reading about the basics. Copyright ostensibly protects the work from use without permission. That being said, it doesn't work well for digital products (ever downloaded an MP3 without paying a fee?). Still, it's protection at least in name. Technically, you hold the copyright to anything you create anyway, but a copyright notice asserts the fact textually.

You don't need to register with an organization or government to hold copyright on a work. For more info, see the Copyright Basics pdf on the gov site and note specifically the section titled "How to Secure a Copyright".

ShadowIce
01-17-2010, 12:55 AM
Bah. what am I saying? I already have a copyright on my product. I mailed it to myself. I'm just gonna say problem solved...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum