Php help getting total price and number of boxes.....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ashebrian
Forum Contributor
Posts: 103
Joined: Sat Feb 02, 2008 8:01 pm

Php help getting total price and number of boxes.....

Post by ashebrian »

I have a voucher page in html format that a user clicks on a price

Code: Select all

<select name='price' id='price'>
<option value='Price'>Choose Amount</option>
<option value='50'>50 EURO</option>
<option value='100'>100 EURO</option>
<option value='150'>150 EURO</option>
<option value='200'>200 EURO</option>
<option value='250'>250 EURO</option>
<option value='300'>300 EURO</option>
<option value='350'>350 EURO</option>
<option value='400'>400 EURO</option>
<option value='450'>450 EURO</option>
<option value='500'>500 EURO</option>
</select>
and the number of vouchers

Code: Select all

<select name='quantity' id='quantity'>
<option value='0'>None</option>
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
<option value='5'>5</option>
</select>
they want which are both select boxes to buy a particular voucher. I'm trying to use php codes to make this info user friendly to the customers. What i can't achieve is 2 things:
1) whatever price is selected and number of vouchers is selected - i'd like to have them displayed on the next page with the total price eg. if price is 50 and 2 vouchers selected total price is 100.

2) also i can't seem to figure out where to start if i want the number of vouchers selected in the previous page to come up in the next page so the customer can type in the details they want on the vouchers eg. if customer selects 2 vouchers, 2 different voucher boxes like

Code: Select all

<td><p style="font-weight:bold">Presented To</p> <i>(printed on voucher)</i></td>
        <td>
            <input type="text" name="presentedto" size="40" /><b style="color:#FF0000">*</b>    
        </td>
      </tr>
      <tr>
        <td class="formtd"><p style="font-weight:bold">Presented By</p><i>(printed on voucher)</i></td>
        <td><input type="text" name="presentedby" size="40" />
          <b style="color:#FF0000">*</b> 
         </td>
      </tr>
      <tr>
        <td class="formtd"><p style="font-weight:bold">Dedication</p><i>(printed on voucher)</i></td>
        <td><textarea rows="8" cols="40" name="dedication"></textarea>
          <b style="color:#FF0000">*</b> 
        </td>
      </tr>
      <tr>
        <td style="font-weight:bold"><p>Address</p></td>
        <td>
            <input type="text" name="address" size="20" />      
        </td>
      </tr>
      <tr>
        <td><i>(voucher posted to)</i></td>
        <td>
            <input type="text" name="address2" size="20" />     
        </td>
      </tr>
      <tr>
        <td></td>
        <td>
            <input type="text" name="address3" size="20" />     
        </td>
      </tr>
      <tr>
        <td style="font-weight:bold"><p>Email</p></td>
        <td>
            <input type="text" name="emailother" size="20" />       
        </td>
      </tr>
      <tr>
        <td><i>(voucher emailed to)</i></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td><b style="color:#cc0033"><i>Voucher 2 Details:</i></b></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td><p style="font-weight:bold">Presented To</p> <i>(printed on voucher)</i></td>
        <td>
            <input type="text" name="presentedto2" size="40" />     
        </td>
      </tr>
      <tr>
        <td class="formtd"><p style="font-weight:bold">Presented By</p><i>(printed on voucher)</i></td>
        <td><input type="text" name="presentedby2" size="40" />        
        </td>
      </tr>
      <tr>
        <td class="formtd"><p style="font-weight:bold">Dedication</p><i>(printed on voucher)</i></td>
        <td><textarea rows="8" cols="40" name="dedication2"></textarea>        </td>
      </tr>
      <tr>
        <td style="font-weight:bold"><p>Address</p></td>
        <td>
            <input type="text" name="address12" size="20" />        </td>
      </tr>
      <tr>
        <td><i>(voucher posted to)</i></td>
        <td>
            <input type="text" name="address22" size="20" />        </td>
      </tr>
      <tr>
        <td></td>
        <td>
            <input type="text" name="address32" size="20" />        </td>
      </tr>
      <tr>
        <td style="font-weight:bold"><p>Email</p></td>
        <td>
            <input type="text" name="emailother2" size="20" />      </td>
      </tr>
      <tr>
        <td><i>(voucher emailed to)</i></td>
        <td>&nbsp;</td>
      </tr>
comes up in the next page. or if the customer selects 3 voucher, 3 voucher boxes comes up. and so on.

I've tried to use $_POST but i don't get the total with that and i can't post the info for 3 pages in a row(only one). Can you please help as i've been spending 3 days trying to figure this out.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Php help getting total price and number of boxes.....

Post by Christopher »

An easy way to display the total on the next page would be something like:

Code: Select all

<?php
$price = intval($_POST['price']);
$quantity= intval($_POST['quantity']);
echo $price * $quantity;
?>
It that page needs to be submitted then put the price and quantity into hidden inputs.
(#10850)
ashebrian
Forum Contributor
Posts: 103
Joined: Sat Feb 02, 2008 8:01 pm

Re: Php help getting total price and number of boxes.....

Post by ashebrian »

cheers the price worked.

Now my only problem is getting the number of boxes to be displayed. can any one help
Post Reply