Problem saving mysql decimal field

Asked

Viewed 93 times

0

Out of nowhere began a problem I found no explanation. Follow my code, explaining the problem.

Here I receive the data:

$venda = $_POST['f_venda']; //Sim
$preco_venda = $_POST['f_preco_venda']; //360000
$imovel = $_POST['f_imovel']; //2564

$real = 'R$ ' . number_format($preco_venda, 2, ',', '.'); // R$360.000,00

Here I write the data in the table and the problem occurs. The sales field should be updated to 360000, but is recording the number 1, and the sales field should be changed to Yes, but remains in No:

$sql_preco_venda = "UPDATE imoveis SET preco = '$preco_venda' AND venda = '$venda' WHERE controle LIKE '$imovel'";
mysqli_query($connection, $sql_preco_venda);

In these two INSERTS the fields are recorded correctly, that is, $sale records Yes and $real records R$360.000,00:

$sql_rastros = "INSERT INTO rastros VALUES ('0', '$user_nome', now(), now(), 'alterou opção ($venda) e preço de venda do imóvel código $cod_int para $real')";
mysqli_query($connection, $sql_rastros);

$sql_historia = "INSERT INTO historia VALUES ('0', '$user_nome', now(), '$imovel', 'Opção ($venda) e preço de venda alterado para $real')";
mysqli_query($connection, $sql_historia);

I’ve really tried everything and I haven’t detected the error. I appreciate your help.

  • Try removing AND and adding only a COMMA (,) to your UPDATE.

1 answer

1


Surely a syntax error is occurring in your UPDATE.

Instead of you using AND, you should wear a comma (,) to define the value of preco and of venda. The AND should be used for this case, only for WHERE, adding one or more conditions to the update.

How are you:

$sql_preco_venda = "UPDATE imoveis SET preco = '$preco_venda' AND venda = '$venda' WHERE controle LIKE '$imovel'";

As it should be:

$sql_preco_venda = "UPDATE imoveis SET preco = '$preco_venda', venda = '$venda' WHERE controle LIKE '$imovel'";
  • KKK. I spent 8 hours trying to fix a basic thing... I think it’s stress! That’s right, THANK YOU.

  • @Wagnerestilloweb normal, happens to the best families. = D If you have helped, if you want, you can validate the answer. Hugs. Good luck.

  • 1

    All right, I saw.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.