Jump to content

Value stays the same no matter which choice made in dropdown!?!


suess0r

Recommended Posts

Hi,

 

I'm trying to make the selected dropdown match the original choice after the page submits to itself... While doing so I some how managed to make $quantity always = 5000. Can I get a second pair of eyes on this or am i just going crazy? ;x

 

This first part works fine... and an example of what i'm trying to do with the second portion

<select name="postcard-size" size="1">

                <option value="" >-Please Select-</option>

                <option value="postcard4-6"

<?php $size = $_POST['postcard-size'];

if ($size == "postcard4-6") echo "selected: selected"; ?>

>Postcards 4" x 6"</option>

                <option value="postcard85-55"

<?php $size = $_POST['postcard-size'];

if ($size == "postcard85-55") echo "selected: selected"; ?>

>Postcards 8.5" x 5.5"</option>

                <option value="postcard6-11"

<?php $size = $_POST['postcard-size'];

if ($size == "postcard6-11") echo "selected: selected"; ?>

>Postcards 6" x 11"</option>

              </select>

 

This is the part that's giving me trouble - I echo'd $quantity and it's always 5000 no matter what choice they make.

 

   

        <select name="postcard-quantity" size="1">

                <option value="">-Please Select-</option>

                <option value="100"

<?php $quantity = $_POST['postcard-quantity'];

if ($quantity = 100) echo "selected: selected"; ?>

>100</option>

                <option value="250"

<?php $quantity = $_POST['postcard-quantity'];

if ($quantity = 250) echo "selected: selected"; ?>

>250</option>

                <option value="500"

<?php $quantity = $_POST['postcard-quantity'];

if ($quantity = 500) echo "selected: selected"; ?>

>500</option>

<option value="1000"

<?php $quantity = $_POST['postcard-quantity'];

if ($quantity = 1000) echo "selected: selected"; ?>

>1,000</option>

<option value="2500"

<?php $quantity = $_POST['postcard-quantity'];

if ($quantity = 2500) echo "selected: selected"; ?>

>2,500</option>

<option value="5000"

<?php $quantity = $_POST['postcard-quantity'];

if ($quantity = 5000) echo "selected: selected"; ?>

>5,000</option>

              </select>

I thought it might have something to do with the 2nd set of values being all numbers like <option value=5000 instead of "5000" and that didn't help - I also changed it to echo 'selected: "selected"'; but that didn't help either. Appreciate all the help.

Link to comment
Share on other sites

OK - I know this is probably sloppy coding.. but here's the gist of what i'm trying to do. The $total is staying at the bottom value of each If validation section.. So if the $size = postcard4-6 then the $total is always 324.95

 

<?php

$size = $_POST['postcard-size'];

$quantity = $_POST['postcard-quantity'];

$error = 1;

 

echo $size;

echo $quantity;

 

if ($size == "")

$total = 0.00;

if (!isset($quantity))

$total = 0.00;

//Note: Need validation for if isset($size) && !isset($quantity)

 

if (isset($size, $quantity)) {

  //Validation for Postcard 4x6

 

      if ($size == "postcard4-6" && $quantity = 100) {

$total = 39.95;

}

if ($size == "postcard4-6" && $quantity = 250){

$total = 79.95;

}

if ($size == "postcard4-6" && $quantity = 500){

$total = 89.95;

}

if ($size == "postcard4-6" && $quantity = 1000){

$total = 114.95;

}

if ($size == "postcard4-6" && $quantity = 2500){

$total = 229.95;

}

if ($size == "postcard4-6" && $quantity = 5000){

$total = 324.95;

}

 

//Validation for Postcard 8.5x5.5

if ($size == "postcard85-55" && $quantity = 100) {

$total = 69.95;

}

if ($size == "postcard85-55" && $quantity = 250){

$total = 119.95;

}

if ($size == "postcard85-55" && $quantity = 500){

$total = 149.95;

}

if ($size == "postcard85-55" && $quantity = 1000){

$total = 229.95;

}

if ($size == "postcard85-55" && $quantity = 2500){

$total = 399.95;

}

if ($size == "postcard85-55" && $quantity = 5000){

$total = 589.95;

}

 

//Validation for Postcard 8.5x5.5

if ($size == "postcard6-11" && $quantity = 100) {

$total = 0.00;

//$error = 2;

 

}

if ($size == "postcard6-11" && $quantity = 250){

$total = 0.00;

//$error = 2;

}

if ($size == "postcard6-11" && $quantity = 500){

$total = 0.00;

//$error = 2;

}

if ($size == "postcard6-11" && $quantity = 1000){

$total = 349.95;

}

if ($size == "postcard6-11" && $quantity = 2500){

$total = 499.95;

}

if ($size == "postcard6-11" && $quantity = 5000){

$total = 799.95;

}

}

$total = number_format($total, 2, '.', '');

echo '$'.$total;

//if ($error = 2)

//echo "$0.00 <br> Sorry, you need to select 1,000+ to get postcards in 6x11";

// echo '  <input type="hidden" name="amount" value="'.$total.'">';

  ?>

 

I've tried swapping the '=' with '==' in the if statement..

ex: if ($size == "postcard6-11" && $quantity == 1000){

$total = 349.95;

 

that didn't help. I echo'd my $size and $quantity and i'm getting all the right values - like in the above example i get $size = postcard6-11 and $quantity = 1000.. i'm sure i'm just doing something stupid (my PHP is a bit rusty)..

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.