# How to use a variable dollar amount in php\_payment sample?

**URL:** <https://developer.squareup.com/forums/t/how-to-use-a-variable-dollar-amount-in-php-payment-sample/3035>\
**Category:** Questions\
**Tags:** payments-api\
**Created:** [July 15, 2021, 8:25pm UTC](https://developer.squareup.com/forums/t/how-to-use-a-variable-dollar-amount-in-php-payment-sample/3035 "2021-07-15T20:25:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![westonp688](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@westonp688](https://developer.squareup.com/forums/u/westonp688)\
**Post date:** [July 15, 2021, 8:25pm UTC](https://developer.squareup.com/forums/t/how-to-use-a-variable-dollar-amount-in-php-payment-sample/3035/1 "2021-07-15T20:25:02Z")

</div>

Hi again,

My payment form works fine with the hardcoded dollar value in the example:

$money-\>setAmount(100);

However, I want to use a variable amount there, which is determined in my app depending on what the user is buying. I put that dollar value into a session variable called ‘square\_total’ and want to use it in process-payment.php as follows:

$money-\>setAmount($\_SESSION[‘square\_total’]);

But I keep getting this error on the form:

“amount\_money supplied was malformed”

Is there a simple way I am missing to be able to replace that hard-coded $1 in the sample code, with a variable amount determined by my local app?

Thanks!

---

<div class="post-metadata">

**Author:** ![westonp688](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@westonp688](https://developer.squareup.com/forums/u/westonp688)\
**Post date:** [July 15, 2021, 8:27pm UTC](https://developer.squareup.com/forums/t/how-to-use-a-variable-dollar-amount-in-php-payment-sample/3035/2 "2021-07-15T20:27:40Z")

</div>

For example, my code sets the following when someone goes to purchase a $135 item:

$\_SESSION[‘square\_total’] = “13500”;

Then I try to use that in process-payment.php as follows:

$money-\>setAmount($\_SESSION[‘square\_total’]);

---

<div class="post-metadata">

**Author:** ![westonp688](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@westonp688](https://developer.squareup.com/forums/u/westonp688)\
**Post date:** [July 15, 2021, 10:53pm UTC](https://developer.squareup.com/forums/t/how-to-use-a-variable-dollar-amount-in-php-payment-sample/3035/3 "2021-07-15T22:53:16Z")

</div>

OK I figured it out… Turns out I just had to add an include at the top of process-payment.php, to call in my session code that is already included on all my other pages.

Without that include, process-payment.php did not have access to session variables of course. Duh.

All good now, you can ignore this post 🙂

---

<div class="post-metadata">

**Author:** ![Bryan-Square](https://sea1.discourse-cdn.com/square/forums/user_avatar/developer.squareup.com/bryan-square/32/38_2.png) [@Bryan-Square](https://developer.squareup.com/forums/u/Bryan-Square)\
**Post date:** [July 16, 2021, 4:20pm UTC](https://developer.squareup.com/forums/t/how-to-use-a-variable-dollar-amount-in-php-payment-sample/3035/4 "2021-07-16T16:20:48Z")

</div>

Glad to hear you figured it out. 🙂
