how to take a value from the table and sum with which to enter php

Asked

Viewed 246 times

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?

that I’ve already done esse e meu banco

<?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

  • I already did that didn’t work out

  • but that’s how it’s done. you must have missed something in your code

  • <?php&#xA;$idConta=$_POST['idConta'];&#xA;$valor=$_POST['valor'];&#xA;&#xA;$consu= mysql_query("select saldo from conta where idConta=$idConta");&#xA;&#xA;$atualizado = $consu + $valor;&#xA;&#xA;$up = mysql_query("UPDATE conta SET saldo='$atualizado' WHERE idConta=$idConta"); ?>

  • 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...

1 answer

0

1 - select tabelaSaldoAtual ,
2 -  armazena na em uma variavel  ex: var saldoAtual
3 -  pega o valor que ele depositou e salva em outra variavel. ex: var deposito
4 - NovoSaldo = saldoAtual + deposito
5 - $up = mysql_query("UPDATE conta SET saldo='$NovoSaldo'  WHERE idConta=$idConta")
  • <?php&#xA;$idConta=$_POST['idConta'];&#xA;$valor=$_POST['valor'];&#xA;&#xA;$consu= mysql_query("select saldo from conta where idConta=$idConta");&#xA;&#xA;$saldoatual = $consu + $valor;&#xA;&#xA;&#xA;$up = mysql_query("UPDATE conta SET saldo='$saldoatual' WHERE idConta=$idConta"); ?>

  • didn’t work out !

Browser other questions tagged

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