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"> ['.$fecha.'] Titulo del mensaje</td>';
echo ' <td class="texto"> '.$row[titulo].'</td>';
echo ' </tr>';
echo ' <tr>';
echo ' <td class="texto" valign=top width=40%> Contenido</td>';
echo ' <td class="texto"> '.nl2br($row[contenido]).'</td>';
echo ' </tr>';
echo ' <tr>';
echo ' <td class="texto"> Su nombre</td>';
echo ' <td class="texto"> '.$row[autor].'</td>';
echo ' </tr>';
echo ' <tr>';
echo ' <td class="texto"> Su correo electronico</td>';
echo ' <td class="texto"> '.$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