Error in data received in PHP

0

This error appeared after the hosting migration.

Warning: number_format() expects parameter 1 to be float, string given in /home/bramo472/public_html/evolucamp.com.br/doutor/_app/Helpers/Orcamento.class.php on line 105

Warning: number_format() expects parameter 1 to be float, string given in /home/bramo472/public_html/evolucamp.com.br/doutor/_app/Helpers/Orcamento.class.php on line 105

Warning: number_format() expects parameter 1 to be float, string given in /home/bramo472/public_html/evolucamp.com.br/doutor/_app/Helpers/Orcamento.class.php on line 105

Warning: number_format() expects parameter 1 to be float, string given in /home/bramo472/public_html/evolucamp.com.br/doutor/_app/Helpers/Orcamento.class.php on line 105

Warning: number_format() expects parameter 1 to be float, string given in /home/bramo472/public_html/evolucamp.com.br/doutor/_app/Helpers/Orcamento.class.php on line 105

Warning: number_format() expects parameter 1 to be float, string given in /home/bramo472/public_html/evolucamp.com.br/doutor/_app/Helpers/Orcamento.class.php on line 105
MENSAGEM
Erro ao cadastrar: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'como_conheceu' in 'field list

Database:

Filethatisaccusedoferror:

//MontaatabelacomositensdocarrinhoprivatefunctionAmmountCart(){if(isset($_SESSION['CARRINHO'])&&!empty($_SESSION['CARRINHO'])):$this->Data['orc_cart']=null;foreach($_SESSION['CARRINHO']as$IDPRO=>$PRODUCT):$produtos.="<tr><td> Código: </td> <td> <strong> {$PRODUCT['prod_codigo']} </strong> </td></tr>";
        $produtos .= "<tr><td> Produto: </td> <td> <strong> {$PRODUCT['prod_title']} </strong> </td></tr>";
        $produtos .= "<tr><td> Valor unitário: </td> <td> <strong> R$ ". number_format($PRODUCT['prod_preco'], 2, ',', '.')." </strong> </td></tr>";
        $produtos .= "<tr><td> Modelos: </td> <td> <strong>Quantidades:</strong> </td></tr>";
        foreach ($PRODUCT['modelos'] as $itens => $quantidade):
          $produtos .= "<tr><td> {$itens} </td> <td> <strong> {$quantidade} </strong> </td></tr>";
        endforeach;
        $produtos .= "<tr style='background: #eee; border-bottom:1px solid #ccc; padding: 2px; height:2px;'><td ></td><td></td></tr>";
      endforeach;
      $produtos .= "<tr><td>Valor total </td><td>R$ {$this->Total}</td></tr>";

      $this->Data['orc_cart'] = $produtos;
    endif;
  }

This is a bug line:

$produtos .= "<tr><td> Valor unitário: </td> <td> <strong> R$ ". number_format($PRODUCT['prod_preco'], 2, ',', '.')." </strong> </td></tr>";
    
asked by anonymous 02.08.2018 / 14:43

2 answers

1

No need to be FLOAT not , number_format perfectly accepts string, see:

echo number_format('2.0', 2);

That is, as long as the format is "understandable" as a number by PHP, it will be worth it.

The problem is that you have rows with null values, and null is not a valid format here, I do not know why this with null can be because it is using JOIN in the query and it is bringing something that should not, if it is not the case of JOIN then it is because it actually has values like NULL , then simply because no one has defined the unit value of the product yet and should not be displayed value, or display a message in place. p>

But from what I see you are using SESSION for a shopping cart, then the problem is probably somewhere else , you should have a method called AddCart or AddProduct (hypothetical) at the time of adding the session you should not be correctly submitting the value of the product, nor should it be sending anything, so $PRODUCT['prod_preco'] probably does not exist , and PHP converts to NULL

Out of error:

  

Error registering: SQLSTATE [42S22]: Column not found: 1054 Unknown column 'as_knowledged' in 'field list

Your query is wrong, it's clearly trying to query the name of a column that does not exist.

    
02.08.2018 / 16:41
-1

It is possible that this new hosting is with the version of PHP 7 and in this version the number_format function expects the first parameter to be a float. It does a type casting using the floatvar function ( link ). Another option is in the query you force the field when null returns 0. If you are using MySQL, use the IFNULL function ( link ).

I hope I have helped.

EDIT

Regarding the type received by the function, it's really not a problem if the value is a string, according to @Guilherme Nascimento's response.

    
02.08.2018 / 15:44