Hi All,

The form below is set to pass data to paypal, however I cant seem to get it to work when using variables recieved from a $_POST.

I get an error from paypal stating........

"The link you have used to enter the PayPal system contains an incorrectly formatted item amount."

all im trying to pass through is a variable 1.

Any advice would be appreciated.

Cheers

Paul

<form target="paypal" action="" method="post"> 
<input type="hidden" name="cmd" value="_cart"> 
<input type="hidden" name="business" value="email@email.com"> 
<input type="hidden" name="add" value="1"> 
<input type="hidden" name="item_name" value="test"> 
<input type="hidden" name="item_number" value="1">
<input type="hidden" name="amount" value="<?php echo $price ?>"> 
<input type="image" src="https://www.paypal.com/images/x-click-but22.gif" border="0" name="submit" alt="Make payments with PayPal - it’s fast, free and secure!"> 
</form>

Dani AI

Generated

A common cause of PayPal's "incorrectly formatted item amount" is that the value sent in amount contains non‑numeric characters (hidden HTML, currency symbols, thousands separators, or locale commas). In this thread tracked the problem to stray markup appended to the price; 's nudge to confirm the variable is set is also useful — both checking presence and cleaning the content are needed.

Sanitize and normalize the posted price on the server before printing it into the form. The steps are: trim and strip tags, convert comma decimals to a dot if needed, remove any non‑digit/period characters, validate numeric, then format to two decimal places. Example:

$raw  = filter_input(INPUT_POST, 'price', FILTER_SANITIZE_STRING);
$raw  = strip_tags(trim($raw));
$raw  = str_replace(',', '.', $raw);                 // unify decimal separator
$raw  = preg_replace('/[^0-9.]/', '', $raw);         // drop currency, whitespace, tags
if (!is_numeric($raw)) { /* handle error */ }
$amount = number_format((float)$raw, 2, '.', '');

When debugging, view the generated HTML source to inspect the value attribute, var_dump() the raw input before formatting, or dump bin2hex() to reveal hidden bytes. Always output the final value safely inside the attribute (escape HTML) and ensure there are no thousands separators or currency characters left. Also confirm the correct PayPal fields are used for the chosen flow and include currency_code if appropriate.

Note: server‑side validation is mandatory — never rely on client input being well formed. These steps prevent the most common formatting rejections from PayPal and make the integration more robust going forward.

Recommended Answers

All 2 Replies

I could be wrong as my php is not that strong, but your echo statement looks incorrect

try <?php echo($price); ?>

Also are you setting the value of $price? i.e. you're not sending a null value are you?

Hi Thanks for the response.

I found the issue. My own stupid fault. I have a habit of concatenating line breaks, so when i was passing what i thought was 1, it was actually 1<br>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.