este es el codigo que tengo
Código PHP:
<?php require_once('Connections/tesis.php'); ?>
<?php
//initialize the session
if (!isset($_SESSION)) {
session_start();
}
// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
$logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
//to fully log out a visitor we need to clear the session varialbles
$_SESSION['MM_Username'] = NULL;
$_SESSION['MM_UserGroup'] = NULL;
$_SESSION['PrevUrl'] = NULL;
unset($_SESSION['MM_Username']);
unset($_SESSION['MM_UserGroup']);
unset($_SESSION['PrevUrl']);
$logoutGoTo = "default.php";
if ($logoutGoTo) {
header("Location: $logoutGoTo");
exit;
}
}
?>
<?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;
}
}
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;
}
}
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;
}
}
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;
}
}
$colname_Recordset1 = "-1";
if (isset($_POST['MM_Username'])) {
$colname_Recordset1 = $_POST['MM_Username'];
}
mysql_select_db($database_tesis, $tesis);
$query_Recordset1 = sprintf("SELECT * FROM usuario WHERE usuEmail = %s", GetSQLValueString($totalRows_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $tesis) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$colname_carrito = "%";
if (isset($_SESSION['MM_Username'])) {
$colname_carrito = $_SESSION['MM_Username'];
}
mysql_select_db($database_tesis, $tesis);
$query_carrito = sprintf("SELECT empresas.empNombre, productos.proNombre, carrito.carCantidad, carrito.carFecha, carrito.proPrecio, carrito.carCodigo, carrito.usuEmail FROM carrito Inner Join empresas ON empresas.empRut = carrito.empRut Inner Join productos ON productos.proCodigo = carrito.proCodigo WHERE carrito.usuEmail = %s ORDER BY carCodigo ASC", GetSQLValueString($colname_carrito, "text"));
$carrito = mysql_query($query_carrito, $tesis) or die(mysql_error());
$row_carrito = mysql_fetch_assoc($carrito);
$totalRows_carrito = mysql_num_rows($carrito);
?>
<!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>Documento sin título</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<p> </p>
<table width="40%" height="79" border="1">
<tr>
<th width="12%" scope="col">Fecha</th>
<th width="7%" scope="col">Empresa</th>
<th width="7%" scope="col">Producto</th>
<th width="12%" scope="col">Cantidad</th>
<th width="12%" scope="col">Total</th>
<th width="50%" scope="col">Acciones</th>
</tr>
<?php do { ?>
<tr>
<th height="20" scope="row"><?php echo $row_carrito['carFecha']; ?> <strong></strong></th>
<td align="center" valign="middle"><?php echo $row_carrito['empNombre']; ?></td>
<td><?php echo $row_carrito['proPrecio']; ?></td>
<td align="center"><input name="carCantidad[]" type="text" id="carCantidad[]" value="<?php echo $row_carrito['carCantidad']; ?>" size="2 value=" <?php if (!(strcmp($row_carrito['carCantidad'],0))) {echo "texted=\"texted\"";} ?><?php echo $row_carrito['carCantidad']?>"/></td>
<td align="center"><?php echo $row_carrito['proPrecio']; ?></td>
<td align="center"><strong><a href="del_carro.php?carCodigo=<?php echo $row_carrito['carCodigo']; ?>"><img src="templates/1/sources/html/images/trash.gif" alt="d" width="12" height="14" /></a></strong></td>
</tr>
<?php } while ($row_carrito = mysql_fetch_assoc($carrito)); ?>
<tr>
<th height="22" colspan="6" scope="row">SUBTOTAL =
<?php $carrito=mysql_query("select proPrecio from carrito");
while ($row_carrito = mysql_fetch_assoc($carrito))
$total= $row_carrito['proPrecio'] + $row_carrito['proPrecio'];
echo $total //muestra la suma total
?></th>
</tr>
</table>
</form>
<a href="<?php echo $logoutAction ?>">Desconectar</a>
</body>
</html>
<?php
mysql_free_result($carrito);
?>
como pueden ver es un juego de registros simple que me lista los productos de la tabla carrito que se guardan en mi bd...
trate de hacer una suma simple al final pero no me resulto , lo de las cantidad tpco lo entiendo mucho como poder conservarlas asiendo un actualizar