para dar de alta un producto Código HTML:
<form action="cart.php" method="post">
<?php
while($row = mysql_fetch_array($_pagi_result))
{
?>
<tr>
<td width="10%" height="25">
<font face="verdana" size="1" color="black">
<?php echo $row["codigo_producto"]; ?> </font> </td>
<td width="25%" height="25">
<font face="verdana" size="1" color="black">
<?php echo $row["detalle_producto"]; ?> </font> </td>
<td width="10%" height="25">
<font face="verdana" size="1" color="black">
<?php echo $row["capacidad_producto"]; ?> </font> </td>
<td width="20%" height="25">
<font face="verdana" size="1" color="black">
$<?php echo $row["precio_producto"]; ?> </font> </td>
<td width="10%" height="25">
<input name="cantprod_pedido" type="text" size="5">
</td>
<td width="10%" height="25">
</td>
<td width="10%" height="25"><label>
<input type="submit" name="add_item" id="agregar" value="Agregar">
</label></td>
<td width="10%" height="25">
</td>
</tr>
<input type="hidden" name="id_prod" value="<?php echo $row["id_producto"]; ?>" size="5">
</form>
Llama a las funciones y hace la eliminación del producto
Código PHP:
if ($add_item)
{
AddItem($_POST["id_prod"]);
ShowCart();
}
if ($remove_item)
{
RemoveItem($_GET["id_prod"]);
ShowCart();
}
function AddItem($id_prod)
{
$Host = "localhost";
$User = "root";
$Password = "";
$Base = "pedidos";
$Tabla = "pedido";
//conecta la base
$Link = mysql_connect ($Host, $User, $Password) or die("Error vp conexion ".mysql_error());
mysql_select_db($Base, $Link) or die("Error select db ".mysql_error());
$Query = "insert into pedido (id_pedido, id_sessionpedido, id_userpedido, fecha_pedido, id_prod, cantprod_pedido) values('', '".$_SESSION['Sid']."', '".$_SESSION['k_userid']."', '".$_SESSION['k_fecha']."', '".$_POST['id_prod']."', '".$_POST['cantprod_pedido']."')";
$insertar = mysql_query($Query);
}
function RemoveItem($id_prod)
{
$Host = "localhost";
$User = "root";
$Password = "";
$Base = "pedidos";
$Tabla = "pedido";
//conecta la base
$Link = mysql_connect ($Host, $User, $Password) or die("Error vp conexion ".mysql_error());
mysql_select_db($Base, $Link) or die("Error select db ".mysql_error());
mysql_query("delete from pedido where id_prod = $id_prod");
}
function ShowCart()
{
$Host = "localhost";
$User = "root";
$Password = "";
$Base = "pedidos";
//conecta la base
$Link = mysql_connect ($Host, $User, $Password) or die("Error vp conexion ".mysql_error());
mysql_select_db($Base, $Link) or die("Error select db ".mysql_error());
$result = mysql_query("select producto.id_producto, producto.codigo_producto, producto.tipo_producto, producto.detalle_producto, producto.capacidad_producto, producto.precio_producto, pedido.id_pedido, pedido.id_sessionpedido, pedido.id_userpedido, pedido.id_prod, pedido.cantprod_pedido from producto inner join pedido on producto.id_producto = pedido.id_prod" );
$totalCost = 0;
?>
<html>
<head>
<title> Carrito de Compras </title>
</head>
<body bgcolor="#ffffff">
<h1>Carrito de Compras</h1>
<form name="frmCart" method="get">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="10%" height="25" bgcolor="#FF9900">
<font face="verdana" size="1" color="white">
<b>Código</b>
</font>
</td>
<td width="10%" height="25" bgcolor="#FF9900">
<font face="verdana" size="1" color="white">
<b>Cantidad</b>
</font>
</td>
<td width="15%" height="25" bgcolor="#FF9900">
<font face="verdana" size="1" color="white">
<b>Tipo de Producto</b>
</font>
</td>
<td width="25%" height="25" bgcolor="#FF9900">
<font face="verdana" size="1" color="white">
<b>Producto</b>
</font>
</td>
<td width="10%" height="25" bgcolor="#FF9900">
<font face="verdana" size="1" color="white">
<b>Capacidad</b>
</font>
</td>
<td width="15%" height="25" bgcolor="#FF9900">
<font face="verdana" size="1" color="white">
<b>Precio x Unidad</b>
</font>
</td>
<td width="15%" height="25" bgcolor="#FF9900">
<font face="verdana" size="1" color="white">
<b>Subtotal</b>
</font>
</td>
<td width="10%" height="25" bgcolor="#FF9900">
<font face="verdana" size="1" color="white">
<b>Eliminar?</b>
</font>
</td>
</tr>
<form action="cart.php" method="post">
<?php
while($row = mysql_fetch_array($result))
{
// Increment the total cost of all items
$totalCost += ($row["cantprod_pedido"] * $row["precio_producto"]);
?>
<tr>
<td width="10%" height="25">
<font face="verdana" size="1" color="black">
<?php echo $row["codigo_producto"]; ?>
</font>
</td>
<td width="10%" height="25">
<font face="verdana" size="1" color="black">
<?php echo $row["cantprod_pedido"]; ?>
</font>
</td>
<td width="15%" height="25">
<font face="verdana" size="1" color="black">
<?php echo $row["tipo_producto"]; ?>
</font>
</td>
<td width="25%" height="25">
<font face="verdana" size="1" color="black">
<?php echo $row["detalle_producto"]; ?>
</font>
</td>
<td width="10%" height="25">
<font face="verdana" size="1" color="black">
<?php echo $row["capacidad_producto"]; ?>
</font>
</td>
<td width="15%" height="25">
<font face="verdana" size="1" color="black">
$<?php echo number_format($row["precio_producto"], 2, ".", ","); ?> </font>
</td>
<td width="15%" height="25">
<font face="verdana" size="1" color="black">
$<?php echo number_format($row["cantprod_pedido"] * $row["precio_producto"], 2, ".", ","); ?> </font>
</td>
<td width="10%" height="25">
</td>
<td width="10%" height="25"><label>
<input type="submit" name="remove_item" id="agregar" value="Eliminar">
</label></td>
</tr>
<input type="text" name="id_prod" value="<?php echo $row["id_producto"]; ?>" size="5">
<?php
}
?>
?>
Gracias por tu paciencia, la verdad estoy enredada en eso y no se como solucionarlo.