1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

php math's functions help

Discussion in 'PHP' started by ianhaney, Jul 11, 2013.

  1. #1
    Hi

    I need some help with php math functions

    I have added a php order form to my website at the following

    http://www.irhwebsites.co.uk/web-design-order-form.php

    I have added a total deposit to pay now field

    Two issues, one is I want the total to be divided into 2 and then that figure displayed in the total deposit to pay now input field

    Second issue is after filling the details and clicking submit, I have made extra text saying total deposit to pay now, I want that to display the total price divided by 2 and then the paypal button to know that number divided into 2 and taken through to PayPal

    At the moment the paypal button is just taking the total price and going through to PayPal

    I can send over php files if that is possible through PM or by email if anyone wants to email me at

    Thank you in advance

    Kind regards

    Ian
    ianhaney, Jul 11, 2013 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    17,423
    Likes Received:
    1,741
    Best Answers:
    37
    Trophy Points:
    510
    #2
    Sounds pretty straightforward... how about you post the relevant bits of code that are causing trouble and wrap them in [ php] bbcode.
    sarahk, Jul 11, 2013 IP
    ColorWP.com likes this.
  3. ianhaney

    ianhaney Greenhorn

    Messages:
    72
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #3
    Hi sarahk

    Thank you for the reply

    I have posted below the relevant coding

    If need be, I can zip the file and attach it

    PHP:
    1.  
    2.     // total row
    3.     $tbl->addRow();
    4.         $tbl->addCell( 'Total: ', 'total', 'data', array('colspan'=>3) );
    5.         $tbl->addCell( $frm->addInput('text', 'total', 0, array('readonly'=>true, 'size'=>8, 'class'=>'cur') ) );
    6.    
    7.                 // total deposit row
    8.     $tbl->addRow();
    9.         $tbl->addCell( 'Total deposit to pay now: ', 'totaldeposit', 'data', array('colspan'=>3) );
    10.         $tbl->addCell( $frm->addInput('text', 'totaldeposit', 0, array('readonly'=>true, 'size'=>8, 'class'=>'cur') ) );
    Below is the paypal button code

    Code (Text):
    1. <form action="https://www.paypal.com/cgi-bin/webscr" method="post" style="margin-top: 3%;">
    2.     <input type="hidden" name="cmd" value="_xclick" />
    3.     <input type="hidden" name="business" value="$paypal_email" />
    4.     <input type="hidden" name="amount" value="$totaldeposit" /> - see where I added deposit to the word total, it was just total before
    5.     <input type="hidden" name="currency_code" value="GBP">
    6.     <input type="hidden" name="item_name" value="$desc" />
    7.     <input type="hidden" name="custom" value="$custom" />
    8.     <input type="hidden" name="return" value="$return_url" />
    9.     <input type="hidden" name="cancel_return" value="$cancel_url" />
    10.     <input type="image" name="submit "border="0"
    11.         src="https://www.paypalobjects.com/en_US/i/btn/btn_buynow_LG.gif"
    12.         alt="PayPal - The safer, easier way to pay online" />
    13. </form>
    Bit more PHP below

    PHP:
    1. if ( $str === '' ) {
    2.         $str = '<p>You didn\'t order anything.</p>';
    3.     } else {
    4.         $str = '<h2 class="ordertitle">Your Order:</h2>' . $str . '<br>' .'<p>Total: £' .  number_format($total, 2) . '<br><br>' . 'Total Deposit to pay now: £' . number_format($total, 2) . '</p>' . getPayPalBtn($totaldeposit);
    5.     }
    6.    
    7.     return $str;
    8. }
    Hope that all helps

    Ian
    ianhaney, Jul 11, 2013 IP
  4. scriptjerk

    scriptjerk Member

    Messages:
    35
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    33
    #4
    Can you not access that $total variable and just do this before you call the button?

    PHP:
    1. $totaldeposit = $total/2;
    scriptjerk, Jul 13, 2013 IP