You have two immediate problems in the code: You are not checking whether the POST value is correct, and mixing multiplication with concatenation. Test with this:
$valorasercalculado = $_POST['loc']; // valor original
echo "Valor original: $valorasercalculado <br>";
$quantos_porcento = 75/100; //isso equivale a 7.5%
echo "Porcentagem: $quantosporcento <br>";
$loc = $quantos_porcento * $valor_a_ser_calculado;
echo "Resultado: $loc <br>";
In this case, you will only have warnings if any of the values are not numerical.
The ideal would be to rethink something along these lines:
$valorasercalculado = isset($_POST['loc']) ? $_POST['loc'] : 0;
Or even
if (!isset($_POST['loc'])) die 'Valor não fornecido';
right at the beginning of the code.
As well remembered by fellow @Rafaelsalomao, PHP has a specific function to test if a value is numerical. Joining the two ideas:
if (!isset($_POST['loc'])) die 'Valor não fornecido';
if (!is_numeric($_POST['loc'])) die 'O valor precisa ser numérico';
(remembering that ! before the function means "not", in the above cases, if the value is NOT set, the script stops. If the value is NOT numerical, the script also stops).
Handbook:
http://php.net/manual/en/function.isset.php
http://php.net/manual/en/function.is-numeric.php
$loc = ($quantos_porcento * $valor_a_ser_calculado ). "\n";
– Bacco
Separate the numeric part of the string part with parentheses. Also, check that the POST value is correct first of all.
– Bacco
I put the relatives and gave error, and yes the value of the post is correct.
– João Pedro Almeida
The one where I have to put the relatives exactly?
– João Pedro Almeida