Jump to content

SieRobin

Members
  • Posts

    212
  • Joined

  • Last visited

    Never

About SieRobin

  • Birthday 10/25/1985

Profile Information

  • Gender
    Male
  • Location
    New Jersey

SieRobin's Achievements

Member

Member (2/5)

0

Reputation

  1. I hate it when people echo their HTML for the entire page :[ It looks so sloppy and there is no syntax coloring.
  2. Why don't you just serialize and unserialize your object? It will save all of your objects variables.
  3. That's pretty sloppy coding lol. Indent your If statements they look atrocious. I'm sorry if I sound rude but I agree with btherl, your problem will be very obvious when you do lol.
  4. Here are some screenshots of the process. I even serialized and unserialized my object, that way it would store EVEN the object's variables. After submit 2, they're magically set to 0.. and I know why? As you can clearly see it's a new session. As you can see the variables are clearly put into the session. So they ARE stored, right? Now as you can see the variables that WERE recorded are at 0, really like what is that? If anyone knows the problem, please shout it out because it's frustrating.
  5. Just to show you, maybe you can get it to work. I tried controlling the subtotal by a session, here it is. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Ma and Pa - General Goods</title> </head> <body> <?php session_start(); echo session_id(); $snugQuant = $_POST["quantity1"]; $shamQuant = $_POST["quantity2"]; $hercQuant = $_POST["quantity3"]; $slapQuant = $_POST["quantity4"]; $mightyQuant = $_POST["quantity5"]; $snugCheck = $_POST["product1"]; $shamCheck = $_POST["product2"]; $hercCheck = $_POST["product3"]; $slapCheck = $_POST["product4"]; $mightyCheck = $_POST["product5"]; if ($snugCheck) { $snugtotal = $snugQuant * 19.95; } if ($shamCheck) { $shamtotal = $shamQuant * 19.95; } if ($hercCheck) { $herctotal = $hercQuant * 9.95; } if ($slapCheck) { $slaptotal = $slapQuant * 24.95; } if ($mightyCheck) { $mightytotal = $mightyQuant * 19.95; } if ($_POST['submit1']) { $hidden = "hidden"; } else { $hidden = "Submit"; } ?> <form name="transaction" action="project.php" method="post"> <p> <b>Snuggie - $19.95 ea.</b> <input type="checkbox" name="product1" <?php if ($_POST['product1']) echo ' checked="checked"'; ?>> <input type="text" name="quantity1" value="<?php echo $snugQuant; ?>"> <br> <b>Shamwow - $19.95 5 pk.</b> <input type="checkbox" name="product2" <?php if ($_POST['product2']) echo ' checked="checked"'; ?>> <input type="text" name="quantity2" value="<?php echo $shamQuant; ?>"> <br> <b>Hercules Hook - $9.95 30 pk.</b> <input type="checkbox" name="product3" <?php if ($_POST['product3']) echo ' checked="checked"'; ?>> <input type="text" name="quantity3" value="<?php echo $hercQuant; ?>"> <br> <b>Slap Chop - $24.95 ea.</b> <input type="checkbox" name="product4" <?php if ($_POST['product4']) echo ' checked="checked"'; ?>> <input type="text" name="quantity4" value="<?php echo $slapQuant; ?>"> <br> <b>Mighty Mendit - $19.95 ea.</b> <input type="checkbox" name="product5" <?php if ($_POST['product5']) echo ' checked="checked"'; ?>> <input type="text" name="quantity5" value="<?php echo $mightyQuant; ?>"> </p> <input type="<?php echo $hidden; ?>" name="submit1" value="Submit"> </form> <?php $obj = new shipping; $obj->setSubTotal($snugtotal, $shamtotal, $herctotal, $slaptotal, $mightytotal); $_SESSION['subtotal'] = $obj->getSubTotal(); print_r($_SESSION); echo "<br>"; if ($_POST['submit1']) { echo "Your subtotal for this order is: $" . $_SESSION['subtotal'] . "<br>"; ?> <form name="shipping" action="project.php?subtotal=<?php echo $obj->getSubTotal(); ?>" method="post"> <p> <b>1st Class Shipping - $19.99</b> <input type="radio" name="shipping1" value="1"><br> <b>2nd Class Shipping - $14.99</b> <input type="radio" name="shipping1" value="2"><br> <b>Standard Shipping - $5.95</b> <input type="radio" name="shipping1" value="3"> </p> <input type="submit" name="submit2" value="Submit"> <input type="submit" name="back" value="Back"> </form> <?php } if ($_POST['submit2']) { $obj->setShipping($_POST['shipping1']); $obj->setTotal($_SESSION['subtotal'], $obj->getShipping()); echo "Your total for this order is: $" . $obj->getTotal() . "<br>"; echo $obj->getShippingInfo(); } class shipping { public $subtotal; public $snugtotal; public $shamtotal; public $herctotal; public $slaptotal; public $mightytotal; public $shipping; public $shipping1; public $shippingInfo; public $total; public function setSubTotal($snugtotal, $shamtotal, $herctotal, $slaptotal, $mightytotal) { $this->snugtotal = $snugtotal; $this->shamtotal = $shamtotal; $this->herctotal = $herctotal; $this->slaptotal = $slaptotal; $this->mightytotal = $mightytotal; $this->subtotal = $snugtotal + $shamtotal + $herctotal + $slaptotal + $mightytotal; } public function getSubTotal() { return $this->subtotal; } public function setTotal($subtotal, $shipping) { $this->subtotal = $subtotal; $this->shipping = $shipping; $this->total = $subtotal + $shipping; } public function getTotal() { return $this->total; } public function setShipping($shipping1) { $this->shipping1 = $_POST["shipping1"]; if ($this->shipping1 == "1") { $this->shipping = 19.99; $this->shippingInfo = "Your order will arrive in 1 day."; } elseif ($this->shipping1 == "2") { $this->shipping = 14.99; $this->shippingInfo = "Your order will arrive in 2-3 days."; } elseif ($this->shipping1 == "3") { $this->shipping = 5.95; $this->shippingInfo = "Your order will arrive in 5-7 days."; } } public function getShipping() { return $this->shipping; } public function getShippingInfo() { return $this->shippingInfo; } } ?> </body> </html> Anyway, if you can tell me if I did something wrong let me know. But when you hit the first button, the subtotal is in $_SESSION['subtotal'] and when the second button is pressed the variable is set to 0. Don't ask me why or how it's occurring but it is. Please try it out, copy my code and plug it in and give it a run, that's what it does for me lol. Edit: Also you can notice that the session ID is never changed therefore it's the same session, but the variable keeps resetting lol.
  6. I tried to use sessions, but deleted the code because it didn't work. If you think you can make it work why don't you just try it with one of the variables? I couldn't get it to work, however perhaps you're right I wasn't using them correctly but I believe I was lol. If you can post me a quick tutorial on sessions of what I don't know, that'd be cool too. Thank you in advance. Edit: Also, when I used sessions, I posted an array of what was in each session variable.. before and after the second submit button was hit. The variables were in session when the first was hit.. NATURALLY, when the second was hit, the variables were null.
  7. As I stated before, sessions don't work. When the next submit button is activated it reloads project.php, therfore creating a new session?
  8. Nevermind, solved I got it. I used a GET to pull the subtotal out of the address. It works, not the exact way I wanted it to but it did what I wanted it to. Only problem with this is, GET can be altered very easily. Thank you for the help though.
  9. Anyone know how this can be done by using two different forms? What's the easiest way to do it?
  10. Ok quick update. This hidden field doesn't work.. it's still deleting all variables when the action is called from the second form. This is obnoxious and quite frankly I think almost impossible to be done.
  11. I tried sessions and still on the next submit to project.php it will still throw the variables out of the session, which makes no sense at all. However, I have it set to show the next form on an isset that the submit1 button was hit. This means nothing however, since when you hit the second submit button, the action is for project.php again, deleting all the variables from the first spin. Like I said, I'm used to Java where Java always initiates space in memory to fill in variables and holds them till the app is done. I'm not used to programming in PHP without a database, which would make this problem 10 times easier. Anyhow, if I use one form, it works perfectly but the object of the assignment is to use multiple forms. Also, I'm not interested at this point in what way the user can alter the information, it doesn't even work yet so why would I care at this point? I will try the hidden text field as you presented although I didn't want to do that. If that's the only way however then I'll use it. Thank you though :]
  12. Ok so I kind of got what you said and made progress. If I use one form instead of two it works fine, since it's not posting from two different forms just one. However, how do I do this with two? Problem is when the second submit button is pressed quantity1, quantity2, etc.. have no values, therefore it can't calculate anything. So how would I do this?
  13. Hmmn confused sorry. I'm used to scripting in Java that the class will retain those values until the end of the program and the garbage collector comes around and picks it up. However, I'm not understanding what you're saying I guess. If the subtotal is stored in a variable, why wouldn't I be able to just access it still?
  14. Hi I need help with an application that needs to be created for school. It all works aside from when it gets to the bottom of the script it will not calculate the total price including the shipping cost. I've been slaving over it for quite some time now and could really use some help. Here's the code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Ma and Pa - General Goods</title> </head> <body> <?php $snugQuant = $_POST["quantity1"]; $shamQuant = $_POST["quantity2"]; $hercQuant = $_POST["quantity3"]; $slapQuant = $_POST["quantity4"]; $mightyQuant = $_POST["quantity5"]; $snugCheck = $_POST["product1"]; $shamCheck = $_POST["product2"]; $hercCheck = $_POST["product3"]; $slapCheck = $_POST["product4"]; $mightyCheck = $_POST["product5"]; if (isset($snugCheck)) { $snugtotal = $snugQuant * 19.95; } if (isset($shamCheck)) { $shamtotal = $shamQuant * 19.95; } if (isset($hercCheck)) { $herctotal = $hercQuant * 9.95; } if (isset($slapCheck)) { $slaptotal = $slapQuant * 24.95; } if (isset($mightyCheck)) { $mightytotal = $mightyQuant * 19.95; } ?> <form action="project.php" method="post"> <p> <b>Snuggie - $19.95 ea.</b> <input type="checkbox" name="product1"> <input type="text" name="quantity1"> <br> <b>Shamwow - $19.95 5 pk.</b> <input type="checkbox" name="product2"> <input type="text" name="quantity2"> <br> <b>Hercules Hook - $9.95 30 pk.</b> <input type="checkbox" name="product3"> <input type="text" name="quantity3"> <br> <b>Slap Chop - $24.95 ea.</b> <input type="checkbox" name="product4"> <input type="text" name="quantity4"> <br> <b>Mighty Mendit - $19.95 ea.</b> <input type="checkbox" name="product5"> <input type="text" name="quantity5"> </p> <input type="submit" name="submit1" value="Submit"> </form> <?php $obj = new shipping; $obj->setSubTotal($snugtotal, $shamtotal, $herctotal, $slaptotal, $mightytotal); echo "Your subtotal for this order is: $" . $obj->getSubTotal() . "<br>"; if (isset($_POST['submit1'])) { ?> <form action="project.php" method="post"> <p> <b>1st Class Shipping - $19.99</b> <input type="radio" name="shipping1" value="1"><br> <b>2nd Class Shipping - $14.99</b> <input type="radio" name="shipping1" value="2"><br> <b>Standard Shipping - $5.95</b> <input type="radio" name="shipping1" value="3"> <input type="submit" name="back" value="Back"> <input type="submit" name="submit2" value="Submit"> </p> </form> <?php } if (isset($_POST['submit2'])) { $obj->setShipping($_POST['shipping1']); $obj->setTotal($obj->getSubTotal(), $obj->getShipping()); echo "Your total for this order is: $" . $obj->getTotal() . "<br>"; echo $obj->getShippingInfo(); } class shipping { private $subtotal; private $snugtotal; private $shamtotal; private $herctotal; private $slaptotal; private $mightytotal; private $shipping; private $shipping1; private $shippingInfo; private $total; public function setSubTotal($snugtotal, $shamtotal, $herctotal, $slaptotal, $mightytotal) { $this->snugtotal = $snugtotal; $this->shamtotal = $shamtotal; $this->herctotal = $herctotal; $this->slaptotal = $slaptotal; $this->mightytotal = $mightytotal; $this->subtotal = $snugtotal + $shamtotal + $herctotal + $slaptotal + $mightytotal; } public function getSubTotal() { return $this->subtotal; } public function setTotal($subtotal, $shipping) { $this->subtotal = $subtotal; $this->shipping = $shipping; $this->total = $subtotal + $shipping; } public function getTotal() { return $this->total; } public function setShipping($shipping1) { $this->shipping1 = $_POST["shipping1"]; if ($this->shipping1 == "1") { $this->shipping = 19.99; $this->shippingInfo = "Your order will arrive in 1 day."; } elseif ($this->shipping1 == "2") { $this->shipping = 14.99; $this->shippingInfo = "Your order will arrive in 2-3 days."; } elseif ($this->shipping1 == "3") { $this->shipping = 5.95; $this->shippingInfo = "Your order will arrive in 5-7 days."; } } public function getShipping() { return $this->shipping; } public function getShippingInfo() { return $this->shippingInfo; } } ?> </body> </html> Anyhow, if you'd like to plug the code in yourself and give it a run from localhost, please do. It won't calculate the total at all. Thanks in advance.
×
×
  • 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.