I am trying to make a calculator that figures out the total price
(calculates tax sums up price for print size times quantity etc.) and
the mechanism all works fine - but only when the user checks
SEQUENTIALLY from their list of available picture. 

The user should be able to select from their list of pictures at random,
and the script should be able to calculate the total price, but after
one image is skipped, if any pictures after the skipped one is selected
the script thinks that the user chose size 4x6 and quantity of 1 for
those (those are default values) 

note that I am also using arrays and that may be what is causing
problem, - bad array data input. Please help if u can and it doesn't
take u too much time.

The page that gives me trouble is order_form.php

This is what calculated the total value:

(don't get overwhelmed by the code, at the bottom there is clearer
explanation)

________________________________________________

# calculate pricing
if (isset($_POST['check_price']) && isset($_SESSION['f_username']) &&
isset($quantity) && isset($size)) {
        # if no picture checked but update submitted, then lets thell
the user how stupid they are
        if (empty($check))
        {       
                echo ('One or more pictures must be checked in order to
verify price.');
                exit;
        }
                
        # let us do some math, like taxes, discounts, etc.
        for ($i=0; $i<sizeof($_POST['check']); $i++)
        {
                # if the data in the quantity is not pure numbers then
we abort
                if (!is_numeric($quantity[$i]))
                {       
                        echo ('Quantity must be defined only in
numbers.');
                        exit;
                }
                
                # getting the array data into variables
                $ins_size = $size[$i];
                $ins_quantity = $quantity[$i];
                
                ######################
                # 4x6 pricing matrix #
                ######################
                
                # less than or equal to 50
                if ($ins_size == '4x6' && $ins_quantity <= '50')
                {
                        $price = '0.49';
                }
                
                # 51 to 100
                if ($ins_size == '4x6' && $ins_quantity >= '51' &&
$ins_quantity <= '100')
                {
                        $price = '0.45';
                }
                
                # 101 to 150
                if ($ins_size == '4x6' && $ins_quantity >= '101' &&
$ins_quantity <= '150')
                {
                        $price = '0.40';
                }
                
                # 151 to infinity
                if ($ins_size == '4x6' && $ins_quantity >= '151')
                {
                        $price = '$0.30';
                }
                
                ##########################
                # 2.5x3.5 pricing matrix #
                ##########################
                
                # less than or equal to 50
                if ($ins_size == '2.5x3.5' && $ins_quantity <= '50')
                {
                        $price = '0.49';
                }
                
                # 51 to 100
                if ($ins_size == '2.5x3.5' && $ins_quantity >= '51' &&
$ins_quantity <= '100')
                {
                        $price = '0.45';
                }
                
                # 101 to 150
                if ($ins_size == '2.5x3.5' && $ins_quantity >= '101' &&
$ins_quantity <= '150')
                {
                        $price = '0.40';
                }
                
                # 151 to infinity
                if ($ins_size == '2.5x3.5' && $ins_quantity >= '151')
                {
                        $price = '0.30';
                }
                
                ########################
                # 3.5x5 pricing matrix #
                ########################
                
                # less than or equal to 50
                if ($ins_size == '3.5x5' && $ins_quantity <= '50')
                {
                        $price = '0.49';
                }
                
                # 51 to 100
                if ($ins_size == '3.5x5' && $ins_quantity >= '51' &&
$ins_quantity <= '100')
                {
                        $price = '0.45';
                }
                
                # 101 to 150
                if ($ins_size == '3.5x5' && $ins_quantity >= '101' &&
$ins_quantity <= '150')
                {
                        $price = '0.40';
                }
                
                # 151 to infinity
                if ($ins_size == '3.5x5' && $ins_quantity >= '151')
                {
                        $price = '0.30';
                }
                
                ######################
                # 5x7 pricing matrix #
                ######################
                
                # less than or equal to 50
                if ($ins_size == '5x7' && $ins_quantity <= '50')
                {
                        $price = '1.99';
                }
                
                # 51 to 100
                if ($ins_size == '5x7' && $ins_quantity >= '51' &&
$ins_quantity <= '100')
                {
                        $price = '1.99';
                }
                
                # 101 to 150
                if ($ins_size == '5x7' && $ins_quantity >= '101' &&
$ins_quantity <= '150')
                {
                        $price = '1.99';
                }
                
                # 151 to infinity
                if ($ins_size == '5x7' && $ins_quantity >= '151')
                {
                        $price = '1.99';
                }
                
                #######################
                # 8x10 pricing matrix #
                #######################
                
                # less than or equal to 50
                if ($ins_size == '8x10' && $ins_quantity <= '50')
                {
                        $price = '4.99';
                }
                
                # 51 to 100
                if ($ins_size == '8x10' && $ins_quantity >= '51' &&
$ins_quantity <= '100')
                {
                        $price = '4.99';
                }
                
                # 101 to 150
                if ($ins_size == '8x10' && $ins_quantity >= '101' &&
$ins_quantity <= '150')
                {
                        $price = '4.99';
                }
                
                # 151 to infinity
                if ($ins_size == '8x10' && $ins_quantity >= '151')
                {
                        $price = '4.99';
                }
                
                #######################
                # 8x12 pricing matrix #
                #######################
                
                # less than or equal to 50
                if ($ins_size == '8x12' && $ins_quantity <= '50')
                {
                        $price = '4.99';
                }
                
                # 51 to 100
                if ($ins_size == '8x12' && $ins_quantity >= '51' &&
$ins_quantity <= '100')
                {
                        $price = '4.99';
                }
                
                # 101 to 150
                if ($ins_size == '8x12' && $ins_quantity >= '101' &&
$ins_quantity <= '150')
                {
                        $price = '4.99';
                }
                
                # 151 to infinity
                if ($ins_size == '8x12' && $ins_quantity >= '151')
                {
                        $price = '4.99';
                }
                
                ########################
                # 11x14 pricing matrix #
                ########################
                
                # less than or equal to 50
                if ($ins_size == '11x14' && $ins_quantity <= '50')
                {
                        $price = '8.99';
                }
                
                # 51 to 100
                if ($ins_size == '11x14' && $ins_quantity >= '51' &&
$ins_quantity <= '100')
                {
                        $price = '8.99';
                }
                
                # 101 to 150
                if ($ins_size == '11x14' && $ins_quantity >= '101' &&
$ins_quantity <= '150')
                {
                        $price = '8.99';
                }
                
                # 151 to infinity
                if ($ins_size == '11x14' && $ins_quantity >= '151')
                {
                        $price = '8.99';
                }
                
                ########################
                # 12x18 pricing matrix #
                ########################
                
                # less than or equal to 50
                if ($ins_size == '12x18' && $ins_quantity <= '50')
                {
                        $price = '14.99';
                }
                
                # 51 to 100
                if ($ins_size == '12x18' && $ins_quantity >= '51' &&
$ins_quantity <= '100')
                {
                        $price = '14.99';
                }
                
                # 101 to 150
                if ($ins_size == '12x18' && $ins_quantity >= '101' &&
$ins_quantity <= '150')
                {
                        $price = '14.99';
                }
                
                # 151 to infinity
                if ($ins_size == '12x18' && $ins_quantity >= '151')
                {
                        $price = '14.99';
                }
                
                # do the math for each print
                $cost_total = ($price * $ins_quantity);
                # $tax isset at the beginning of page
                $cost_tax = ($cost_total * $tax);
                $cost = ($cost_total + $cost_tax);
                
                # to round sintax
                # round(1.95583, 2);
                
                echo ('Size: <b>'.$ins_size.'</b> Quantity:
<b>'.$ins_quantity.'</b> Price: <b>$'.round($cost, 2).'</b><br />');
                
                # put each cost value into an array to hold
                $cost_cache[$i] = round($cost, 2);
                
        }
        
        # calculate total
        $total = array_sum($cost_cache);
        
        
        echo ('<br />Total: '.$total);
        exit;
        
}

______________________________________________

and this is the form:

______________________________________________


<h4>Please select from below the pictures you want printed:</h4>
                
                <form name="order" method="post" action="">'
        );

        mysql_db(); # engage connection

        # Formulate the query 
        $picture_list = mysql_query
        (
                "SELECT ID, picture_name 
                FROM kodak_user_pictures 
                WHERE username = '$_SESSION[f_username]'"
        )
        or die ('Unable to execute query. 1 '.mysql_error());

        # start table for the pictures
        echo 
        (
                '<table>
                        <tr>
                                <td colspan="2">
                                        <b>Picture name</b>
                                </td>
                                <td>
                                        <b>Size</b>
                                </td>
                                <td>
                                        <b>Quantity</b>
                                </td>
                        </tr>'
        );
        
        # show user's pictures
        while ($row = mysql_fetch_array($picture_list)) 
        { 
                # Insert query info into variable
                $ID = $row["ID"];
                $picture_name = $row["picture_name"];

                # Strip down slashes
                $picture_name = stripslashes($picture_name);

                # show available pictures
                echo 
                (
                        '<tr>
                                <td> 
                                        <input type="checkbox"
name="check[]" value="'.$ID.'">
                                </td>
                                <td>
                                        '.$picture_name.'
                                </td>
                                <td>
                                        <select name="size[]">
                                                <option
value="2.5x3.5">2.5x3.5</option>
                                                <option
value="3.5x5">3.5x5</option>
                                                <option value="4x6"
selected="selected">4x6</option>
                                                <option
value="5x7">5x7</option>
                                                <option
value="8x10">8x10</option>
                                                <option
value="8x12">8x12</option>
                                                <option
value="11x14">11x14</option>
                                                <option
value="12x18">12x18</option>
                                        </select>
                                </td>
                                <td>
                                        <input name="quantity[]"
type="text" value="1" size="3" maxlength="3">
                                </td>
                        </tr>'
                );
                
        } # end show available pictures
        
        # see if the total was calculated, if not then say 0.00
        if (isset($total))
        {
                $total = $total;
        }
        else
        {
                $total = '0.00';
        }
        
        echo 
        (
                '</table>
                
                <br />
                
                Total cost: <b> $'.$total.'</b> <input type="submit"
name="check_price" value="Update">
                
                <h4>When finished setting order press "Submit".</h4>
                
                <input type="submit" name="make_order" value="Submit">
                <input type="reset" name="reset" value="Reset">
                 or
                <a href="picture_manager.php">Cancel</a>
                
                </p> 
                
                </form>'



_____________________________________________________

It might help to see the forms html code:

This can be viewed at:

http://rapidphotoimagecentre.com/picture_manager/order_form.php 

(Login: test pass: test) <- will be in use by me

Make a new user (your name whatever) at:

http://rapidphotoimagecentre.com/picture_manager/

__________________________________________

the arrays are: 

size[];

quantity[];

and 

check[];


so here is and example of the problem:

this is the default:

Picture name                            Size            Quantity
hitachi_4_color.gif             4x6             1
rough_dubs.gif                  4x6             1
system_sound.gif                        4x6             1
peeSnow3.jpg                    4x6             1
bobsqu.gif                              4x6             1
Bluehills.jpg                   4x6             1

Then the use chooses the first two pictures to print:

Size: 4x6 Quantity: 1 Price: $0.56
Size: 5x7 Quantity: 1 Price: $2.29

Total: 2.85

So it works, these are the values I chose, but if I skip one picture it
will get screwed up:

This is what gets calculated:

Size: 4x6 Quantity: 1 Price: $0.56
Size: 5x7 Quantity: 2 Price: $4.58
Size: 4x6 Quantity: 1 Price: $0.56

Total: 5.7

And his is what I actually selected:

Size: 4x6 Quantity: 1 Price: $0.56
Size: 5x7 Quantity: 2 Price: $4.58
Size: 8x10 Quantity: 5 Price: $???

Total: 5.7


Thanks, 

Vic





______________________________________________________________________ 
Post your free ad now! http://personals.yahoo.ca

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to