Foros del Web » Programando para Internet » PHP »

Libro De Visitas

Estas en el tema de Libro De Visitas en el foro de PHP en Foros del Web. Tengo el siguiente libro y me tira este error: Código PHP: <?php $host  =  'localhost' ; $usuario  =  'root' ; $password  =  'jime1976' ; $base  ...
  #1 (permalink)  
Antiguo 14/08/2007, 10:50
Avatar de jimadri  
Fecha de Ingreso: julio-2006
Ubicación: Buenos Aires
Mensajes: 487
Antigüedad: 17 años, 10 meses
Puntos: 1
Libro De Visitas

Tengo el siguiente libro y me tira este error:
Código PHP:
<?php

$host 
'localhost';
$usuario 'root';
$password 'jime1976';
$base 'libro';

$conexion mysql_connect("$host""$usuario""$password") or die("Error en la conexion");
$base mysql_select_db("$base") or die("Error en la conexion");



if (
$_POST[enviar]) {

if (
$_POST[titulo] and $_POST[contenido] and $_POST[autor])    {

    
$sql "select max(idmensaje) as M from mensajes";
    
$res mysql_query($sql);
    
$row mysql_fetch_array($res);
    if (
$row['M'] > 0)        $max $row['M'] +1;
    else                    
$max=1;    

    
$fecha date("Y-m-d");

    
$sql "insert into mensajes (idmensaje, titulo, contenido, fecha, autor, email) values ($max, '$_POST[titulo]', '$_POST[contenido]', '$fecha', '$_POST[autor]', '$_POST[email]')";
    
$res mysql_query($sql);        

    
header ("Location: $_SERVER[PHP_SELF]");
} else                                                        {
    
$error 'Por Favor Ingrese su Nombre + Titulo y Contenido del Mensaje.';
}
}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
       <title>Libro de Visitas!</title>

<style>
td.texto    {
    font-family: "Trebuchet MS";
    font-size: 12px;
    background-color: #E5ECF9;
    border:solid 1px #000000;
}
td.mensaje    {
    font-family: "Trebuchet MS";
    font-size: 14px;
    color: #990000;
}
input        {
    border:solid 1px #000000;
}
</style>

</head>
<body>


<?php

$sql 
'select * from mensajes order by fecha desc';
$res mysql_query($sql);
if (
mysql_num_rows($res))    {

    
$ames[1] = 'Enero';
    
$ames[]  = 'Febrero';
    
$ames[]  = 'Marzo';
    
$ames[]  = 'Abril';
    
$ames[]  = 'Mayo';
    
$ames[]  = 'Junio';
    
$ames[]  = 'Julio';
    
$ames[]  = 'Agosto';
    
$ames[]  = 'Septiembre';
    
$ames[]  = 'Octubre';
    
$ames[]  = 'Noviembre';
    
$ames[]  = 'Diciembre';

    while (
$row mysql_fetch_array($res))    {

        
$fecha explode("-"$row[fecha]);
        
$dia $fecha[2];
        
$mes $ames[abs($fecha[1])];
        
$año $fecha[0];
        
$fecha "$dia de $mes de $año";

        echo 
'<table cellspacing="0" cellpadding="2" border="1" align="center" width=90%>';
        echo 
'    <tr>';
        echo 
'        <td class="texto">&nbsp;['.$fecha.'] Titulo del mensaje</td>';
        echo 
'        <td class="texto">&nbsp;'.$row[titulo].'</td>';
        echo 
'    </tr>';

        echo 
'    <tr>';
        echo 
'        <td class="texto" valign=top width=40%>&nbsp;Contenido</td>';
        echo 
'        <td class="texto">&nbsp;'.nl2br($row[contenido]).'</td>';
        echo 
'    </tr>';

        echo 
'    <tr>';
        echo 
'        <td class="texto">&nbsp;Su nombre</td>';
        echo 
'        <td class="texto">&nbsp;'.$row[autor].'</td>';
        echo 
'    </tr>';

        echo 
'    <tr>';
        echo 
'        <td class="texto">&nbsp;Su correo electronico</td>';
        echo 
'        <td class="texto">&nbsp;'.$row[email].'</td>';
        echo 
'    </tr>';

        echo 
'</table>';

        echo 
'<br>';

    }
} else                        {
        
$mensaje 'Sea el primero en ingresar un comentario en nuestro libro !';
    }

?>

<FORM action="" method="POST">

<?php

if ($mensaje)
    echo 
'<table align="center"><tr><td class="mensaje">'.$mensaje.'</td></tr></table><br>';

if (
$error)
    echo 
'<table align="center"><tr><td class="mensaje">'.$error.'</td></tr></table><br>';

?>

<table cellspacing="0" cellpadding="2" border="1" align="center" width=65%>
    <tr>
        <td class="texto">Titulo del mensaje</td>
        <td class="texto"><input type="text" name="titulo" size="20" value="<?php echo $_POST[titulo]; ?>"></td>
    </tr>

    <tr>
        <td class="texto" valign=top>Contenido</td>
        <td class="texto"><textarea name="contenido" rows=10 cols=30><?php echo $_POST[contenido]; ?></textarea></td>
    </tr>

    <tr>
        <td class="texto">Su nombre</td>
        <td class="texto"><input type="text" name="autor" size="20" value="<?php echo $_POST[autor]; ?>"></td>
    </tr>

    <tr>
        <td class="texto">Su correo electronico [ opcional ]</td>
        <td class="texto"><input type="text" name="email" size="20" value="<?php echo $_POST[email]; ?>"></td>
    </tr>

    <tr>
    <td class="texto" colspan="2" align="center"><input type="submit" name=enviar value="Agregar Comentario"></td>
    </tr>

</table>

</FORM>

</body>
</html>
ERROR:Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\libro.php on line 19

Warning: Cannot modify header information - headers already sent by (output started at C:\AppServ\www\libro.php:19) in C:\AppServ\www\libro.php on line 28
  #2 (permalink)  
Antiguo 14/08/2007, 11:57
Avatar de mauled  
Fecha de Ingreso: marzo-2005
Ubicación: Cd. de México.
Mensajes: 3.001
Antigüedad: 19 años, 1 mes
Puntos: 33
Re: Libro De Visitas

Lo que sucede es que no existe ningun resultado en este consulta

Código PHP:
$sql "select max(idmensaje) as M from mensajes"
Por lo que manda un error a pantalla, esto a su vez no permite que se ejecute la función header() puesto que antes de esta función no puede haber ningun tipo de salida hacia el explorador.

Verfica que tu tabla tenga información.

Saludillos.
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 21:56.