Ver Mensaje Individual
  #2 (permalink)  
Antiguo 24/05/2003, 04:32
Avatar de Pino
Pino
 
Fecha de Ingreso: abril-2003
Ubicación: Cangas do Morrazo, Pontevedra, Galicia, España, Europa, etc
Mensajes: 490
Antigüedad: 21 años
Puntos: 0
Hola, aquí te paso un codigo. Tiene 5 campos: autor, titulo, web, e-mail y mensaje.

Estructura de la base de datos:
Código PHP:
CREATE TABLE libro (
  
fecha int(10NOT NULL default '0',
  
autor varchar(100NOT NULL default '',
  
titulo varchar(255NOT NULL default '',
  
web varchar(255NOT NULL default '',
  
mail varchar(255NOT NULL default '',
  
noticia text NOT NULL
TYPE=MyISAM
Para firmar el en libro: admin.php
Código PHP:
<?php

$host 
"localhost"//Suele ser localhost
$user "tu_user"//poner aqui el nombre de usuario
$pass "tu_pass"//aqui el pass
$dbname "nombre_de_tu_base_de_datos";

if (
$enviaFirma
{
$conecta mysql_connect($host,$user,$pass); //conecta a la db
mysql_select_db($dbname,$conecta); //selecciona la tuya
$time time(); //establecemos el tiempo actual para la fecha
mysql_query("insert into libro (fecha, autor, titulo, web, mail, noticia) values ('$time', '$autor', '$titulo', '$web', '$mail', '$noticia')");
mysql_close($conecta); //cierra la conexion
echo "As Firmado en el Libro de Visitas. <a href=\"librodevisitas.php\">Ver el Libro</a><br><br>";
}
?>

<html>
<head>
<title>Firmar Libro de Visitas</title>
</head>

<body background="fondolynx.gif">
<b>Firmar libro de visitas<br>
<form method="post" action="admin.php">
Autor:<input type="text" name="autor" size="25"><br>
Titulo:<input type="text" name="titulo" size="40"><br>
Web:&nbsp;&nbsp;<input type="text" name="web" value="http://" size="60"><br>
E-mail:<input type="text" name="mail" size="60"><br>
Comentario:<textarea name="noticia" value="noticia extendida" cols="60" rows="5"></textarea><br>
<br><input type="submit" name="enviaFirma" value="Firmar" class="boton">
</form>
</body>
</html>
Y este para leer el libro: librodevisitas.php
Código PHP:
<html>
<head>
<title>Libro de VisitaS</title>
</head>

<body background="fondolynx.gif" text="white">
<?php

function traducirCodigo($noticia
 {
 
$noticia str_replace("[b]""<b>"$noticia);
 
$noticia str_replace("[/b]""</b>"$noticia);
 
$noticia str_replace("[i]""<i>"$noticia);
 
$noticia str_replace("[/i]""</i>"$noticia);
 
$noticia str_replace("[u]""<u>"$noticia);
 
$noticia str_replace("[/u]""</u>"$noticia);
 
$noticia str_replace("[c]""<font color='#004080'>"$noticia);
 
$noticia str_replace("[/c]""</font>"$noticia);
 
$noticia str_replace ("[tk]""<img src='imagenes/tk.gif' width='15' height='15'>"$noticia);
 
$noticia eregi_replace (":)""<img src='imagenes/sonrisa.gif' width='15' height='15'>"$noticia);
 
$noticia eregi_replace (":D""<img src='imagenes/divertido.gif' width='15' height='15'>"$noticia);
 
$noticia eregi_replace (";)""<img src='imagenes/ojo.gif' width='15' height='15'>"$noticia);
 return 
$noticia;
 }
$mostrar "10"//noticias a mostrar

$host "localhost"//Suele ser localhost
$user "tu_user";
$pass "tu_pass";
$dbname "nombre_de_tu_base_de_datos";
//--------------------------------------------------------------------------

$conecta mysql_connect($host,$user,$pass); //conecta a la db
mysql_select_db($dbname,$conecta); //selecciona la tuya

$query "select * from libro order by fecha desc";
$resp mysql_query($query);
while (
$datos mysql_fetch_array($resp)) {
     if (
$mostrar 0) {
          
$fecha date("d/m/Y",$datos[fecha]); 
          
$texto traducirCodigo($datos[noticia]);
          echo 
"
          <table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\" bgcolor=\"#000000\">
          <tr>
          <td bgcolor=\"#00000F\">
          <div align=\"center\"><font face=\"Tahoma\" size=\"3\">$datos[titulo]</font></div><div align=\"right\"><font face=\"tahoma\" size=\"1\">Firma del día:: $fecha</font></div>
          </td>
          </tr>
          <tr>
          <td bgcolor=\"rgb(6,41,117)\"> 
          <p align=\"center\"><font face=\"Tahoma\" size=\"2\" color=\"white\">$texto</font></p>
          <br>
          <p align=\"left\"><font face=\"Tahoma\" size=\"2\" color=\"white\">Autor de la Firma = <b>$datos[autor]</b>&nbsp;&nbsp;&nbsp;Visitar web:<a href=\"$datos[web]\">&nbsp;$datos[web]</a>&nbsp;E-mail:<a href=\"mailto:$datos[mail]\">&nbsp;$datos[mail]</a></font></p>
          </td>
          </tr>
          </table>
          <br>
          \n"
;
          
$mostrar--;
     }
}

mysql_query($query); //insertamos el dato
mysql_close($conecta); //cierra la conexion

?>
</body>
</html>
Ya se que es un poco largo . Puedes incluir emoticons aquí:
Código PHP:
function traducirCodigo($noticia
 {
 
$noticia str_replace("[b]""<b>"$noticia);
 
$noticia str_replace("[/b]""</b>"$noticia);
 
$noticia str_replace("[i]""<i>"$noticia);
 
$noticia str_replace("[/i]""</i>"$noticia);
 
$noticia str_replace("[u]""<u>"$noticia);
 
$noticia str_replace("[/u]""</u>"$noticia);
 
$noticia str_replace("[c]""<font color='#004080'>"$noticia);
 
$noticia str_replace("[/c]""</font>"$noticia);
[
B$noticia str_replace ("[tk]""<img src='imagenes/tk.gif' width='15' height='15'>"$noticia);
 
$noticia eregi_replace (":)""<img src='imagenes/sonrisa.gif' width='15' height='15'>"$noticia);
 
$noticia eregi_replace (":D""<img src='imagenes/divertido.gif' width='15' height='15'>"$noticia);
 
$noticia eregi_replace (";)""<img src='imagenes/ojo.gif' width='15' height='15'>"$noticia);[/B
 return 
$noticia;
 } 
Espero que te sirva un saludo
__________________
Pïno
Webmaster de Programas Lynx
Usuario Registrado de Linux #327681

Mi cuerpo en windows, pero mi mente pensando en linux.