Foros del Web » Programando para Internet » PHP »

Como Sumo valores y los pongo en mySQL

Estas en el tema de Como Sumo valores y los pongo en mySQL en el foro de PHP en Foros del Web. Hola Amigos!! Tengo un problemita aqui, veran ... tengo 4 valores que se ingresan a una base de datos, estos son: valor1 valor2 valor3 total ...
  #1 (permalink)  
Antiguo 13/11/2003, 08:29
 
Fecha de Ingreso: septiembre-2003
Ubicación: Valparaiso
Mensajes: 10
Antigüedad: 20 años, 7 meses
Puntos: 0
Pregunta Como Sumo valores y los pongo en mySQL

Hola Amigos!!

Tengo un problemita aqui, veran ...

tengo 4 valores que se ingresan a una base de datos, estos son:

valor1
valor2
valor3
total

la idea es que tengo que ingresarlos a una base de datos mySql y el problema es que yo no quiero ingresar el total, solo quiero ingresar los otros datos y que el total lo calcule con una formula, pero no se en que momento hago esto.

total=valor1+valor2+valor3

ustedes pueden ayudarme, si es asi se los agradesco muchisimo

desde ya gracias!!
  #2 (permalink)  
Antiguo 13/11/2003, 08:35
Avatar de claudiovega  
Fecha de Ingreso: octubre-2003
Ubicación: Puerto Montt
Mensajes: 3.667
Antigüedad: 20 años, 6 meses
Puntos: 11
y como recibes los datos? desde un formulario?
__________________
Dedicado a proyectos web, actualmente desarrollando un sistema de diseño de flyers online muy fácil de usar.
  #3 (permalink)  
Antiguo 13/11/2003, 08:56
 
Fecha de Ingreso: septiembre-2003
Ubicación: Valparaiso
Mensajes: 10
Antigüedad: 20 años, 7 meses
Puntos: 0
Como Sumo valores y los pongo en mySQL

lo estoy haciendo desde Dreamweaver

asi es que aqui te va el codigo:

<?php require_once('../Connections/connRecaudacion.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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 ventas (fecha_venta, cajera_venta, turno_venta, r_pan, r_molde, r_frio, r_envasado, r_fiambreria, r_pasteles, r_empanadas, r_bresler, r_fono, r_integral, r_helados, r_panpascua, valor_guias, boletas_nulas, gastos, anticipos) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['fecha'], "text"),
GetSQLValueString($_POST['cajera'], "text"),
GetSQLValueString($_POST['turno'], "text"),
GetSQLValueString($_POST['pan'], "double"),
GetSQLValueString($_POST['molde'], "double"),
GetSQLValueString($_POST['frio'], "double"),
GetSQLValueString($_POST['envasado'], "double"),
GetSQLValueString($_POST['fiambreria'], "double"),
GetSQLValueString($_POST['pasteles'], "double"),
GetSQLValueString($_POST['empanadas'], "double"),
GetSQLValueString($_POST['bresler'], "double"),
GetSQLValueString($_POST['fono'], "double"),
GetSQLValueString($_POST['integral'], "double"),
GetSQLValueString($_POST['helados'], "double"),
GetSQLValueString($_POST['panpascua'], "double"),
GetSQLValueString($_POST['valorguias'], "double"),
GetSQLValueString($_POST['boletanula'], "double"),
GetSQLValueString($_POST['gastos'], "double"),
GetSQLValueString($_POST['anticipos'], "double"));

mysql_select_db($database_connRecaudacion, $connRecaudacion);
$Result1 = mysql_query($insertSQL, $connRecaudacion) or die(mysql_error());

$insertGoTo = "mrecauda.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
<html>
<head>
<title>Ingresando datos</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#ffffff">

<form name="form1" method="POST" action="<?php echo $editFormAction; ?>">
<table width="474" border="1" align="center" cellspacing="0">
<tr>
<td colspan="2" rowspan="3">&nbsp;</td>
<td width="36"><div align="right">Fecha </div></td>
<td width="150"><div align="left">
<input name="fecha" type="text" id="fecha" value="2003/mm/dd" size="13">
</div></td>
</tr>
<tr>
<td><div align="right">Cajera</div></td>
<td><div align="left">
<input name="cajera" type="text" id="cajera" size="25">
</div></td>
</tr>
<tr>
<td><div align="right">Turno</div></td>
<td><div align="left">
<input name="turno" type="text" id="turno" size="15">
</div></td>
</tr>
<tr>
<td colspan="4" bgcolor="#FFCC00"><div align="center"><strong>Ingresos</strong></div></td>
</tr>
<tr>
<td width="153">Pan<br>
<input name="pan" type="text" id="pan" size="13"></td>
<td width="117">Mode<br>
<input name="molde" type="text" id="molde" size="13"></td>
<td colspan="2">Frio<br>
<input name="frio" type="text" id="frio" size="13"></td>
</tr>
<tr>
<td>Envasado<br>
<input name="envasado" type="text" id="envasado" size="13"></td>
<td>Fiambrer&iacute;a<br>
<input name="fiambreria" type="text" id="fiambreria" size="13"></td>
<td colspan="2">Pasteles<br>
<input name="pasteles" type="text" id="pasteles" size="13"></td>
</tr>
<tr>
<td>Empanadas<br>
<input name="empanadas" type="text" id="empanadas" size="13"></td>
<td>Bresler<br>
<input name="bresler" type="text" id="bresler" size="13"></td>
<td colspan="2">Fono<br>
<input name="fono" type="text" id="fono" size="13"></td>
</tr>
<tr>
<td>Integral<br>
<input name="integral" type="text" id="integral" size="13"></td>
<td>Helados<br>
<input name="helados" type="text" id="helados" size="13"></td>
<td colspan="2">Pan Pascua<br>
<input name="panpascua" type="text" id="panpascua" size="13"></td>
</tr>
<tr>
<td colspan="2" rowspan="3">&nbsp;</td>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td colspan="2">Total Registrado </td>
</tr>
<tr>
<td colspan="2">Valores x Guias
<input name="valorguias" type="text" id="valorguias" size="13"></td>
</tr>
<tr>
<td colspan="4" bgcolor="#FFCC00"><p align="center"><strong>Gastos Generales</strong></p> </td>
</tr>
<tr>
<td>Boletas Nulas<br>
<input name="boletanula" type="text" id="boletanula" size="13"></td>
<td colspan="3" rowspan="3">&nbsp;</td>
</tr>
<tr>
<td>Gastos<br>
<input name="gastos" type="text" id="gastos" size="13"></td>
</tr>
<tr>
<td>Anticipos<br>
<input name="anticipos" type="text" id="anticipos" size="13"></td>
</tr>
<tr>
<td colspan="2" rowspan="3">&nbsp;</td>
<td colspan="2">Total Descuentos </td>
</tr>
<tr>
<td colspan="2">Total Deposito </td>
</tr>
<tr>
<td colspan="2">Diferencia Caja </td>
</tr>
</table>
<br>
<input type="submit" name="Submit" value="Guardar">
<input type="reset" name="Submit2" value="Limpiar">
<input type="hidden" name="MM_insert" value="form1">
</form>
</div></td>
</tr>
</table>
<p>&nbsp;</p></td>
<td rowspan="2" valign="top"><img name="panaderos" src="../img/panaderos.jpg" width="218" height="160" border="0" alt=""></td>
<td height="166"><img src="../img/png/spacer.gif" width="1" height="166" border="0" alt=""></td>
<td></td>
</tr>
<tr>
<td rowspan="2"><img src="../img/png/spacer.gif" width="1" height="160" border="0" alt=""></td>
<td height="22"></td>
</tr>
<tr>
</div></td>
<td></td>
</tr>
</table>
</body>
</html>
  #4 (permalink)  
Antiguo 13/11/2003, 09:13
Avatar de claudiovega  
Fecha de Ingreso: octubre-2003
Ubicación: Puerto Montt
Mensajes: 3.667
Antigüedad: 20 años, 6 meses
Puntos: 11
la variable que contiene el sql de insercion de registros es: $insertSQL. Esta variable es construida a partir de los datos recibidos del formulario, lo cuales son "tratados" por la funcion GetSQLValueString(), la cual toma el dato y lo pasa a su tipo de dato correcto (con el fin de no provocar error de tipo de datos). Bueno me fui por otro lado, que valores quieres sumar?

por ejemplo, si quieres sumar r_pan + r_helados y guardar ese valor en valorguias, reemplazarias GetSQLValueString($_POST['valorguias'], "double") por:

GetSQLValueString($_POST['pan'], "double")+GetSQLValueString($_POST['helados'], "double")
__________________
Dedicado a proyectos web, actualmente desarrollando un sistema de diseño de flyers online muy fácil de usar.
  #5 (permalink)  
Antiguo 13/11/2003, 17:57
 
Fecha de Ingreso: septiembre-2003
Ubicación: Valparaiso
Mensajes: 10
Antigüedad: 20 años, 7 meses
Puntos: 0
Problemas con calculos

Hola Amigos, miren este es el procedimiento que hago para ingresar datos a una base y no me funciona :( que lata!!

Please necesito ayuda!!

Marcelo




<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
// variebles entrantes
$codigo=$codigo;
$total=$valor1+$valor2+$valor3;

// Conexion con la base de datos
$Host = "localhost";
$User = "root";
$Password = "";
$DBName = "panypandb";
$TableName = "ejemplo";

// Conexion con la tabla
$Link = mysql_connect ($Host, $User, $Password);
$Query = "INSERT into $TableName values('0', '$valor1', '$valor2','$valor3','&total')";

// GetSQLValueString($_POST['valor1'], "int"),
// GetSQLValueString($_POST['valor2'], "int"),
// GetSQLValueString($_POST['valor3'], "int"),
// GetSQLValueString($_POST['total'], "int");

print("La consulta es:<br>$Query<p>\n");
/*
if (mysql_db_query ($DBName, &Query, $Link)){
print("Se Guardo bien!<br>\n");
} else {
print("no se pudo guardar!<br>\n");
}
*/
mysql_close ($Link);

?>
</body>
</html>
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 16:07.