PHP Error after upgrade

On my website Line 24 is returning an error message: Warning: number_format() expects parameter 1 to be double, string given in /home/nt4jhhfzc5sh4y1/public_html/customer_support/pay_my_bill.php on line 24

Line 23: // Receive the posted amount and format it as a dollar amount without the currency symbol
Line 24: $amount = number_format(trim($_POST[“amount”],"$"),2);

This worked fine until we upgraded to PHP/5.4.35

Would appreciate the appropriate code. Thanks.

[php]<?php
$_POST[“amount”] = ‘$10.99’;
$amount = number_format(trim($_POST[“amount”],"$"),2);

echo $amount;[/php]

The above works fine for me and I’m using PHP 5.5. It has to be somewhere else in you’re code. How exactly are you pulling in $_POST[“amount”] with a dollar sign?

Very Strange, I have tried almost everything to break it, but it keeps working for me. :-\

I take that back, when I do this $_POST[“amount”] = ‘$adfadfd’; I get the error. I’m guessing it’s either getting some strange characters or a NULL ("") character in $_POST somehow.

This seems to happen when the “number” ($_POST/$_GET are strings) start with a space. Just add a space to the trim function to remove that as well (you don’t need any spaces at the start/end anyway)

[php]$amount = number_format(trim($_POST[“amount”]," $"),2);[/php]

Good Catch… :wink:

That happens a lot with user input or data fields being pulled in from various sources (I suspect it the latter in this case).

I am afraid fixing the space didn’t correct the error message.

I absolutely stink (for the lack of a better word) debugging php code. So, if I wouldn’t be too imposing, could you take a look at the code so that we can determine why the Error is appearing on Line 24. I can’t seem to locate where the garbage is being input. As you can see, this was a much older code that broke after the update.

I really can’t express my appreciation for any assistance you could provide. See Attachment


php.txt (8.04 KB)

Hm, I can’t reproduce the error after my “fix”. Could you do the following on line 22?

[php]var_dump($_POST[“amount”]); die();[/php]

and paste the output here

Renders a blank page with the letters NULL

Then you arent posting that value to the page

So, why would this code work before, and not now with the higher version of php? That’s what I don’t understand. I think if I downgraded php version, it would work again. Just don’t want to go backwards.

Are you sure the warning was not there before? The upgrade may have changed the error reporting settings, notices and warnings are usually not set to show in production.

Sponsor our Newsletter | Privacy Policy | Terms of Service