Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\hernan\sistema\index.php on line 8
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\hernan\sistema\index.php on line 18
Procesar noticia
Código PHP:
<?php
$link = mysql_connect("localhost", "root", "pass") or die("No se pudo conectar al servidor");
mysql_select_db("noticias", $link) or die("No se pudo conectar a la DB");
$titulo = $_POST['titulo'];
$contenido = $_POST['contenido'];
$fecha = date("Y-m-d");
mysql_query("INSERT INTO noticias (titulo, contenido, fecha) VALUES ('$titulo','$contenido', '$fecha');", $link);
if(!mysql_error()) {
header("location: index.php"); exit();
} else {
echo mysql_error();
}
?>
Código PHP:
<?php
$link = mysql_connect("localhost","root","pass");
mysql_select_db("noticias",$link);
$resultado = mysql_query("SELECT * FROM contenidos ORDER BY id DESC;", $link);
while($datos = mysql_fetch_array($resultado))
{
?>
<h2>$datos['titulo']</h2>
<br />
<p>$datos['contenido']</p>
<br /><div>$datos['fecha']
<a href=ver.php?id=$datos['id']>Comentarios</a>
<?
}//este es el cierre del while
mysql_free_result($resultado);
?>