0
I am making a bank account system and in one of the operations the user has to make deposit only that my doubt this already made the table update that takes the value that the user and changes in the table more as sum with what had in the table
ex
the user puts 100$ more on the table has 50 his balance and to stay 150$
how can I do that?
<?php include 'conecta.php';?>
<html>
<head>
<meta http-equiv="content-Type" content="text/html"; charset="utf-8" />
<title>Realizar Deposito</title>
</head>
<body>
<?php
$idConta=$_POST['idConta'];
$valor=$_POST['valor'];
$sql="insert into trasacoes (idConta,valor) value ('$idConta','$valor')";
$result=mysql_query($sql);
?>
<?php
$idConta=$_POST['idConta'];
$valor=$_POST['valor'];
$up = mysql_query("UPDATE conta SET saldo='$valor' WHERE idConta=$idConta");
?>
first you need to make a select before.... take the value.... add and only then write in the table the updated value
– Israel Zebulon
I already did that didn’t work out
– Faumar Camara
but that’s how it’s done. you must have missed something in your code
– Israel Zebulon
<?php
$idConta=$_POST['idConta'];
$valor=$_POST['valor'];

$consu= mysql_query("select saldo from conta where idConta=$idConta");

$atualizado = $consu + $valor;

$up = mysql_query("UPDATE conta SET saldo='$atualizado' WHERE idConta=$idConta"); ?>
– Faumar Camara
makes a float cast on the two values...and prints the value before updating in the database. checks whether the field type in the database is varchar or float...
– Israel Zebulon