Foros del Web » Programando para Internet » PHP »

Problema con sessiones

Estas en el tema de Problema con sessiones en el foro de PHP en Foros del Web. Que tal estoy haciendo un carrito de compras sencillo pero tengo un problema con las sesiones no se porque me manda este error Warning: session_start(): ...
  #1 (permalink)  
Antiguo 12/06/2004, 22:32
agc
 
Fecha de Ingreso: marzo-2004
Ubicación: USA
Mensajes: 92
Antigüedad: 20 años, 1 mes
Puntos: 0
Pregunta Problema con sessiones

Que tal estoy haciendo un carrito de compras sencillo pero tengo un problema con las sesiones no se porque me manda este error

Warning: session_start(): open(C:\PHP\sessiondata\sess_107d25996ee45bdac0dfb 5667a9fbf7a, O_RDWR) failed: No such file or directory (2) in c:\appserv\www\carrito\db.php on line 43

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at c:\appserv\www\carrito\cart.php:5) in c:\appserv\www\carrito\db.php on line 43

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at c:\appserv\www\carrito\cart.php:5) in c:\appserv\www\carrito\db.php on line 43

Warning: Cannot modify header information - headers already sent by (output started at c:\appserv\www\carrito\cart.php:5) in c:\appserv\www\carrito\db.php on line 44

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in c:\appserv\www\carrito\cart.php on line 47

Notice: A session had already been started - ignoring session_start() in c:\appserv\www\carrito\db.php on line 43

Warning: Cannot modify header information - headers already sent by (output started at c:\appserv\www\carrito\cart.php:5) in c:\appserv\www\carrito\db.php on line 44


mi codigo es este
<html>
<head>


<?php

include("db.php");

switch($_GET["action"])
{
case "add_item":
{
AddItem($_GET["id"], $_GET["qty"]);

ShowCart();
break;
}
case "update_item":
{
UpdateItem($_GET["id"], $_GET["qty"]);
ShowCart();
break;
}
case "remove_item":
{
RemoveItem($_GET["id"]);
ShowCart();
break;
}
default:
{
ShowCart();
}
}

//-----------------31----------------------------------

function AddItem($itemId, $qty)
{
global $dbServer, $dbUser, $dbPass, $dbName;

// Get a connection to the database
$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);

// Check if this item already exists in the users cart table
$result = mysql_query("select count(*) from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId");
$row = mysql_fetch_row($result);
$numRows = $row[0];

if($numRows == 0)
{
// This item doesn't exist in the users cart,
// we will add it with an insert query

@mysql_query("insert into cart(cookieId, itemId, qty) values('" . GetCartId() . "', $itemId, $qty)");

}
else
{
// This item already exists in the users cart,
// we will update it instead

UpdateItem($itemId, $qty);

}
}
//--------------------62-------------------------------

function UpdateItem($itemId, $qty)
{
// Updates the quantity of an item in the users cart.
// If the qutnaity is zero, then RemoveItem will be
// called instead

global $dbServer, $dbUser, $dbPass, $dbName;

// Get a connection to the database
$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);

if($qty == 0)
{
// Remove the item from the users cart
RemoveItem($itemId);
}
else
{
mysql_query("update cart set qty = $qty where cookieId = '" . GetCartId() . "' and itemId = $itemId");
}
}

//-------------------86--------------------------------

function RemoveItem($itemId)
{
// Uses an SQL delete statement to remove an item from
// the users cart

global $dbServer, $dbUser, $dbPass, $dbName;

// Get a connection to the database

$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);

mysql_query("delete from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId");

}

function ShowCart()
{
// Gets each item from the cart table and display them in
// a tabulated format, as well as a final total for the cart

global $dbServer, $dbUser, $dbPass, $dbName;

// Get a connection to the database
$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);

$totalCost = 0;
$result = mysql_query("select * from cart inner join items on cart.itemId = items.itemId where cart.cookieId = '" . GetCartId() . "' order by items.itemName asc");
?>
//----------------116--------------------------------------------

<script language="JavaScript">

function UpdateQty(item)
{
itemId = item.name;
newQty = item.options[item.selectedIndex].text;

document.location.href = 'cart.php?action=update_item&amp;id='+itemId+'&amp ;qty='+newQty;
}

</script>
</head>

<body bgcolor=white lang=EN-GB link=blue vlink=blue style='tab-interval:36.0pt'>

<div class=Section1>
<h1>Your Shopping </h1>

<form name="frmCart" method="get">

<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="15%" height="25" bgcolor="red">
<font face="verdana" size="1" color="white">
&nbsp;&nbsp;<b>Qty</b>
</font>
</td>
<td width="15%" height="25" bgcolor="red">
<font face="verdana" size="1" color="white">
<b>Product</b>
</font>
</td>
<td width="15%" height="25" bgcolor="red">
<font face="verdana" size="1" color="white">
<b>Price Each</b>
</font>
</td>
<td width="15%" height="25" bgcolor="red">
<font face="verdana" size="1" color="white">
<b>Remove ?</b>
</font>
</td>
</tr>


<?php

while($row = mysql_fetch_array($result))
{
// Increment the total cost of all items
$totalCost += ($row["qty"] * $row["itemPrice"]);
?>
<tr>
<td width="15%" height="25">
<font face="verdana" size="1" color="black">

<select name="<?php echo $row["itemId"]; ?>" onChange="UpdateQty(this)">
<?php
for($i = 1; $i <= 20; $i++)
{
echo "<option ";
if($row["qty"] == $i)
{
echo " SELECTED ";
}
echo ">" . $i . "</option>";
}
?>
</select>
</font>
</td>
<td width="55%" height="25">
<font face="verdana" size="1" color="black">
<?php echo $row["itemName"]; ?>
</font>
</td>
<td width="20%" height="25">
<font face="verdana" size="1" color="black">
$<?php echo number_format($row["itemPrice"], 2, ".", ","); ?>
</font>
</td>
<td width="10%" height="25">
<font face="verdana" size="1" color="black">
<a href="cart.php?action=remove_item&id=<?php echo $row["itemId"]; ?>">Remove</a>
</font>
</td>
</tr>
<?php
}

// Display the total
?>
<tr>
<td width="100%" colspan="4">
<hr size="1" color="red" NOSHADE>
</td>
</tr>
<tr>
<td width="70%" colspan="2">
<font face="verdana" size="1" color="black">
<a href="products.php">&lt;&lt; Keep Shopping</a>
</font>
</td>
<td width="30%" colspan="2">
<font face="verdana" size="2" color="black">
<b>Total: $<?php echo number_format($totalCost, 2, ".", ","); ?></b>
</font>
</td>
</tr>
</table>
</form>
</body>
</html>
<?php
}
?>

alguien me puede ayudar
  #2 (permalink)  
Antiguo 13/06/2004, 13:10
 
Fecha de Ingreso: junio-2003
Ubicación: Santiago
Mensajes: 105
Antigüedad: 20 años, 9 meses
Puntos: 1
Al parecer tu problema es que estas enviando codigo HTML antes de la inicializacion de la session.

NO PUEDES enviar NADA de html antes de un session_start(); y ahi a simple vista se ve que las primeras 2 lineas de tu codigo son "<html><head>".

Eso debe ser, espero te sirva.
Un saludo
  #3 (permalink)  
Antiguo 13/06/2004, 13:16
Avatar de sism82  
Fecha de Ingreso: octubre-2003
Ubicación: Guadalajara
Mensajes: 865
Antigüedad: 20 años, 6 meses
Puntos: 1
lo que tonny de dice es cierto, sin embargo tu primer error radica en que la carpeta en donde php.ini indica donde se deben guardar las variables de sesión, NO EXISTE, verifica en tu php.ini tener un directorio válido para la carpeta.

un saludo
  #4 (permalink)  
Antiguo 13/06/2004, 19:05
agc
 
Fecha de Ingreso: marzo-2004
Ubicación: USA
Mensajes: 92
Antigüedad: 20 años, 1 mes
Puntos: 0
Pregunta gracias

gracias pero me pueden explicar donde oh como le tengo que hacer no entiendo que es lo que dicen soy novaton

gracias
  #5 (permalink)  
Antiguo 14/06/2004, 10:06
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
Este directorio existe?
(tal cual ... respetando mayusculas y minusculas)

C:\PHP\sessiondata\

Tiene permisos de escritura?

Y en tu php.ini
session.save_path = .. debe apuntar a ese directorio (de hecho así lo hace pero hay problemas de que no existe . o no tiene permisos de escritura).

Un saludo,
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 11:42.