Ver Mensaje Individual
  #15 (permalink)  
Antiguo 19/01/2010, 06:38
Yurisimo
 
Fecha de Ingreso: julio-2009
Mensajes: 111
Antigüedad: 14 años, 9 meses
Puntos: 0
Respuesta: Usuarios PHP y Mysql

Código PHP:
<?php  
if (isset ($_POST['publicar']) ) {
    
    
$titulo=false;
    
$resumen=false;
    
$noticia=false;
    
$autor=false;
    
    
//TITULO
    
if (empty ($_POST['titulo'])) {
    
$msg='El campo titulo es obligatorio. ';
    
    }else{
    
$titulo=true;
    
$tituloBlog = ($_POST['titulo']);
    
    }
    
    
    
// RESUMEN
        
if (empty ($_POST['resumen'])) {
    
$msg.='El campo resumen es obligatorio. ';
    
    }else{
    
$resumen=true;
    
$resumenBlog =($_POST['resumen']);
    
    }
    
    
    
//NOTICIA
        
if (empty ($_POST['noticia'])) {
    
$msg.='El campo noticia es obligatorio. ';
    
    }else{
    
$noticia=true;
    
$noticiaBlog = ($_POST['noticia']);
    }
    
    
    
//AUTOR
        
if (empty ($_POST['autor'])) {
    
$msg.='El campo autor es obligatorio. ';
    
    }else{
    
$autor=true;
    
$autorBlog = ($_POST['autor']);
    }
    
    
    
    if (
$titulo && $resumen && $noticia && $autor) {
    
$fecha time();
    require_once(
'cnx.php');
    
    
$sql "INSERT INTO noticias (titulo, resumen, noticia, fecha, autor) VALUES ('$tituloBlog','$resumenBlog','$noticiaBlog',$fecha,'$autorBlog')";
    
    if(
mysql_query($sql$idcon)) {
      
$msg'Noticia insertada con exito!';
    }else{
    
$msg'Error en la insercion';
    }
    
    }
    
    
}
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin t&iacute;tulo</title>


</head>

<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form1" id="form1">
<table>
<tr>
    <th ><label for="titulo">Titulo</label></th>
    <td>
      <input type="text" name="titulo" id="titulo" value="<?php echo $_POST['titulo']; ?>" /></td>
  </tr>
  <tr>
    <th><label for="resumen">Resumen</label></th>
    <td>
      <textarea name="resumen" id="resumen" cols="45" rows="3"><?php echo $_POST['resumen']; ?></textarea></td>
  </tr>
  <tr>
    <th> <label for="noticia">Su noticia</label></th>
    <td>
<textarea name="noticia" id="noticia" cols="45" rows="3"><?php echo $_POST['noticia']; ?></textarea>
  </td>
  </tr>
  <tr>
    <th><label for="autor">Autor</label></th>
    <td>
      <input name="autor" type="text" id="autor" value="<?php echo $_POST['autor']; ?>" /></td>
  </tr>
  <tr>
    <td></td>
    <td align="center"><input type="submit" name="publicar" id="publicar" value="Publicar" /></td>
  </tr>
  
</table>
</form>
</body>
</html>
Mira te pongo este ejemplo muy claro y a ver si puedes sacar algo de aqui...

Antes del html pongo el codigo php necesario...

Y en el html esta el formulario...

Espero que te sirva...