[Resolvido] Query
Eae pessoa , preciso de uma ajuda ..
creio que pra alguns vai ser facil , mas como eu sou iniciante eu SEI a lógica do código , mas n sei monta-lo
Vou tentar ser o mais especifico possivel
Eu tenho um database no banco de dados que se chama financas
nesse database contem duas tabelas , com os seguintes nomes e linhas :
• banco
|- id_banco
|- nome_banco
|- numero_banco
|- numero_conta
|- saldo_inicial (é especificamente nessa linha que eu vou precisar de ajuda)
• registro_de_valor
|- id_registro (int,primary key)
|- id_banco
|- tipo
|- valor
No database é só isso , agora os formulários
Formulário cadastrabanco.php
/applications/core/interface/imageproxy/imageproxy.php?img=http://img440.imageshack.us/img440/3973/form1q.jpg&key=63186e7cafa34ba3672a7c78f61e34daa48ac00055f3a8b55152cb6eb9157b25" alt="form1q.jpg" />
Esse é o formulário de inserir Bancos
Repetindo , foquem no Saldo Inicial , que é onde preciso de ajuda
Agora o formulário cadastravalor.php
/applications/core/interface/imageproxy/imageproxy.php?img=http://img841.imageshack.us/img841/4695/form2.jpg&key=16de0815995ec23e78d788c8d4ccbdd742a559829b0621b4db93730338ec1f1d" alt="form2.jpg" />
Perceba que o banco que foi cadastrado anteriormente (Banco do Brasil) aparece automaticamente ali no list field (Selecione seu banco)
Agora a função que eu quero..
Eu quero que no formulário cadastrabanco.php, se a variavel do Tipo(Circulado de laranja na imagem) for = a Crédito , eu quero que ele pegue a variavel Valor que eu coloquei (Circulada de vermelho) e some com a linha do database banco na linha saldo_inicial
Nesse caso , o Saldo inicial que antes eu registrei como $200 (na primeira imagem) ira atualizar para $400 (pois registrei um valor de $200 na segunda imagem)
Já se o valor do Tipo for = Débito , ele tire $200
Nesse caso o saudo inicial do banco atualizaria para 0
Alguem pode me ajudar?
ja ia me esquecendi , o código do cadastravalor.php
<?php require_once('Connections/conn.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO registro_de_valor (id_banco, tipo, valor) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['id_banco'], "text"),
GetSQLValueString($_POST['tipo'], "text"),
GetSQLValueString($_POST['valor'], "text"));
mysql_select_db($database_conn, $conn);
$Result1 = mysql_query($insertSQL, $conn) or die(mysql_error());
}
mysql_select_db($database_conn, $conn);
$query_Recordset1 = "SELECT * FROM banco";
$Recordset1 = mysql_query($query_Recordset1, $conn) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">Selecione seu Banco</td>
<td><label for="id_banco">
<select name="id_banco" id="id_banco">
<?php
do {
?>
<option value="<?php echo $row_Recordset1['id_banco']?>"><?php echo $row_Recordset1['nome_banco']?></option>
<?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
$rows = mysql_num_rows($Recordset1);
if($rows > 0) {
mysql_data_seek($Recordset1, 0);
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
}
?>
</select>
</label></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Tipo:</td>
<td><label for="tipo"></label>
<select name="tipo" id="tipo">
<option value="Pago">Debito</option>
<option value="Não Pago">Credito</option>
</select></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Valor:</td>
<td><input type="text" name="valor" value="" size="10" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><input type="submit" value="Insert record" /></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
<p> </p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>Discussão (10)
Carregando comentários...