Ver Mensaje Individual
  #1 (permalink)  
Antiguo 22/10/2005, 05:34
manolain
 
Fecha de Ingreso: marzo-2003
Mensajes: 8
Antigüedad: 21 años, 1 mes
Puntos: 0
No conecta a MySQL cuando hace session_start

Hola a todos, a ver si podeis echarme una mano, porque estoy teniendo problemas muy raros con una web que estoy realizando, que incluye un carrito de la compra. Allá voy:

Tenemos un documento productos.php que muestra los productos. Si no llamamos a la libreria del carrito, todo funciona segun lo esperado:

Código PHP:
<?php

require("inc/funciones.php");


if (
$HTTP_SERVER_VARS["REQUEST_METHOD"]=="GET")
{
    
$idcategoria=$_GET['idcategoria'];
    
$idcategoriamenu=$_GET['idcategoriamenu'];
}
else
{
    
$idcategoria=$_POST['idcategoria'];
    
$idcategoriamenu=$_POST['idcategoriamenu'];
}

if (
maliciosa($idcategoria))  //si detectamos caracter extra&ntilde;o, no mostramos la pagina y vamos al indice
{
    exit(
0);
    
//$redirect = "Location: index.htm";
    //header($redirect);
}
else    
//si no hay nada extra&ntilde;o, continuamos
{
require(
"inc/conexion.php");

$link=conectarse();

[
COLOR="Red"]include("inc/lib_carrito_new.php");[/COLOR]

?>
<html>
<head>
    <title>mkgarena.com - Consultores de marketing deportivo para recintos deportivos</title>
    <?php require("inc/head.php"); ?>
</head>

<body  leftmargin="10" marginwidth="10" marginheight="30" topmargin="30" bgcolor="#000000">

<table border="0" cellspacing="0" cellpadding="0" width="975">

    <tr>

        <td width="350" valign="top">
            <?php require("inc/opciones-tienda.php"); ?>
        </td>

        <td valign="top">
        
            <?php require("inc/menu-superior-tienda.php"); ?><br><br>
        
            <?php
            $sql
="select pr.idpresentacion,pr.nombre as presentacion,pr.caracteristica,pr.precio,e.nombre as entidad,p.idproducto,p.nombre as producto,p.foto,p.descripcion,c.nombre as categoria ";
            
$sql .= "from productos p, entidades e, categorias c,presentaciones pr ";
            
$sql .= "where pr.idproducto=p.idproducto and c.idcategoria=p.idcategoria and p.identidad=e.identidad and p.idcategoria=" $idcategoria;
            
$sql .= " order by p.orden,pr.orden";
            
$result=mysql_query($sql,$link);
            
$row=mysql_fetch_array($result);
            
$num_elem=mysql_num_rows($result);
            
?>
            <table width="90%" align="center" border="0" cellpadding="0" cellspacing="0">
            <tr><td align="center" class="blanco-neg-big"><?php echo $row["categoria"]; ?><br><br></td></tr>
            </table>
            <table width="90%" align="center" border="0" cellpadding="0" cellspacing="0">
            <tr><td align="center" class="amarillo-neg-med">PRODUCTO OFICIAL <?php echo $row["entidad"]; ?><br><br></td></tr>
            </table>
            
            <br><br>
            
            <table bgcolor="#ffffff" width="90%" align="center" border="0" cellpadding="0" cellspacing="0">
            
            <tr><td colspan="5">
                <table  height="6" width="100%" border="0" cellpadding="0" cellspacing="0">
                <tr valign="top">
                    <td height="6" width="6"><img src="../img/esq_sup_izq.gif"></td>
                    <td height="6" >&nbsp;</td>
                    <td height="6" width="6"><img src="../img/esq_sup_dch.gif"></td>
                </tr>
                </table>
            </td></tr>
            
            <tr align="center" class="infoBoxHeading">
                <td colspan="2">&nbsp;</td>
                <td>Producto</td>
                <td>Modelo</td>
                <td>Precio</td>
            </tr>
            <?php 
            
do
            { 
            echo 
$num_elem;
            
?>
            <tr>
                <td width="170" align="center">
                    <a href="<?php echo "producto.php?idcategoria=" $idcategoria "&idpresentacion=" $row["idpresentacion"] . "&idcategoriamenu=" $idcategoriamenu?>">
                    <img border="0" src="../img/<?php echo foto_peq($row["foto"]); ?>" alt="<?php echo $row["producto"]; ?>">
                    </a>
                </td>
                <td width="30" align="center" valign="bottom">
                    <a class="txt-negro-neg" href="javascript:muestra_foto('<?php echo $row["foto"]; ?>','<?php echo $row["presentacion"?>')">
                    <img align="bottom" border="0" src="../img/lupa_zoom.gif" alt="zoom">ZOOM
                    </a>
                </td>
                <td width="310" class="txt-negro-neg" align="center"><?php echo $row["presentacion"]; ?></td>
                <td width="150" class="txt-negro-neg" align="center"><?php echo $row["caracteristica"]; ?></td>
                <td width="150" class="txt-negro-neg" align="center"><?php echo $row["precio"]; ?> &euro;</td>
                
            </tr>
            
            <?php if ($num_elem!=1) { ?>
            <tr><td align="center" valign="middle" colspan="5"><img height="1" width="550" src="../img/linea_negra.jpg"></td></tr>
            
            <?php 
            
}
            
$num_elem--;
            }
            while(
$row=mysql_fetch_array($result)) 
            
?>
            
            </table>
        
            <table bgcolor="#ffffff" width="90%" align="center" border="0" cellpadding="0" cellspacing="0">
            <tr><td>
                <table  height="6" width="100%" border="0" cellpadding="0" cellspacing="0">
                <tr valign="top">
                    <td background="../img/esq_inf_izq.gif" height="6" width="6"></td>
                    <td> <img width="200" height="1" src="../img/blanco1px.gif"></td>
                    <td background="../img/esq_inf_dch.gif" height="6" width="6"></td>
                </tr>
                </table>
            </td></tr>
            </table>
        
        </td>
    </tr>

</table>

<?php 
mysql_free_result
($result);
mysql_close($link); 
}
?>

</body>
</html>
Como podeis ver, al comienzo del documento, podeis ver un include al fichero lib_carrito_new.php

Ahora os copio la clase carrito (que esta en este fichero):

Código PHP:
<?php

class carrito {
    
//atributos de la clase
       
var $num_productos;
       var 
$array_id_prod;
       var 
$array_cantidad_prod;
       var 
$array_nombre_prod;
       var 
$array_precio_prod;

    
//constructor. Realiza las tareas de inicializar los objetos cuando se instancian
    //inicializa el numero de productos a 0
    
function carrito () {
           
$this->num_productos=0;
    }
    
    
//Introduce un producto en el carrito. Recibe los datos del producto
    //Se encarga de introducir los datos en los arrays del objeto carrito
    //luego aumenta en 1 el numero de productos
    
function introduce_producto($id_prod,$nombre_prod,$cantidad,$precio_prod){
        
$this->array_id_prod[$this->num_productos]=$id_prod;
        
$this->array_nombre_prod[$this->num_productos]=$nombre_prod;
        
$this->array_cantidad_prod[$this->num_productos]=$cantidad;
        
$this->array_precio_prod[$this->num_productos]=($precio_prod*$cantidad);
        
$this->num_productos++;
    }

    
//Muestra el contenido del carrito de la compra
    //ademas pone los enlaces para eliminar un producto del carrito
    
function imprime_carrito(){
        
$suma 0;
        echo 
'<table border=1 cellpadding="3">
              <tr>
                <td><b>Nombre producto</b></td>
                <td><b>Precio</b></td>
                <td>&nbsp;</td>
              </tr>'
;
        for (
$i=0;$i<$this->num_productos;$i++){
            if(
$this->array_id_prod[$i]!=0){
                echo 
'<tr>';
                echo 
"<td>" $this->array_nombre_prod[$i] . "</td>";
                echo 
"<td>" $this->array_cantidad_prod[$i] . "</td>";
                echo 
"<td>" $this->array_precio_prod[$i] . "</td>";
                echo 
"<td><a href='eliminar_producto.php?linea=$i'>Eliminar producto</td>";
                echo 
'</tr>';
                
$suma += $this->array_precio_prod[$i];
            }
        }
        
//muestro el total
        
echo "<tr><td><b>TOTAL (iva incluido):</b></td><td> <b>$suma</b></td><td>&nbsp;</td></tr>";
        
//total más IVA
        //echo "<tr><td><b>IVA (16%):</b></td><td> <b>" . $suma * 1.16 . "</b></td><td>&nbsp;</td></tr>";
        
echo "</table>";
    }
    
    
//elimina un producto del carrito. recibe la linea del carrito que debe eliminar
    //no lo elimina realmente, simplemente pone a cero el id, para saber que esta en estado retirado
    
function elimina_producto($linea){
        
$this->array_id_prod[$linea]=0;
    }


//inicio la sesión
[COLOR="Red"]session_start();[/COLOR]
//si no esta creado el objeto carrito en la sesion, lo creo
if (!isset($_SESSION["ocarrito"])){
    
$_SESSION["ocarrito"] = new carrito();
}

?>
Si comento la linea en rojo, la que comprueba el inicio de sesion, todo funciona a la perfeccion, pero si no lo hago, la pagina de productos no muestra nada, pero lo mas extraño, NO MUESTRA NINGUN ERROR (como si la consulta sql no devolviera registros, y entonces continua con la ejecucion de la pagina).

¿Alguno de vosotros podría darme una solución? Muchísimas gracias