formulario
Código HTML:
<form id="form1" name="form1" method="post" action="proceso_de_noticia.php"> <table width="302" height="146" border="0"> <tr> <td colspan="2" class="Estilo1"><div align="center">Ingresar Noticia </div></td> </tr> <tr> <td width="63" class="Estilo1">Titulo</td> <td width="229"><label> <input type="text" name="titulo" /> </label></td> </tr> <tr> <td class="Estilo1">Subcuerpo</td> <td><label> <input type="text" name="despues" /> </label></td> </tr> <tr> <td class="Estilo1">Foto</td> <td><label></label><input type="file" name="foto"/></td> </tr> <tr> <td class="Estilo1">Cuerpo</td> <td><label> <textarea name="cuerpo" rows="5"></textarea> </label></td> </tr> <tr> <td class="Estilo1">Autor</td> <td><label> <input type="text" name="autor" /> </label></td> </tr> </table> <br /> <label> <input type="submit" name="Submit" value="Enviar" /> </label> </form>
proceso del sistema de noticia
Código PHP:
<?php $link=mysql_connect("localhost","root","pass");
mysql_select_db("sistema_de_noticias",$link);
$titulo=($_POST['titulo']);
$despues=($_POST['despues']);
$cuerpo=($_POST['cuerpo']);
$autor=($_POST['autor']);
mysql_query("INSERT INTO tabla (titulo,despues,cuerpo,autor) values ('$titulo','$despues','$cuerpo','$autor')",$link) or die (mysql_error());
header("location:mostrar.php");
?>
Código PHP:
<?php $link= mysql_connect("localhost","root","pass");
mysql_select_db("sistema_de_noticias",$link);
$link=mysql_query("SELECT * FROM tabla ",$link);
$total=mysql_num_rows($link);
while($mostrar=mysql_fetch_array($link)){
echo "<div class='lineas'>$mostrar[titulo]</div><div class='sub'>$mostrar[despues]</div><p><div class='cuerpo'>$mostrar[cuerpo]</p></div><div class='autor'><p>Autor:$mostrar[autor]</p></div>";
}
?>
Código PHP:
<?php $link=mysql_connect("localhost","root","pass");
mysql_select_db("sistema_de_noticias",$link);
if (isset($_POST['submit'])){
if (is_uploaded_file($_FILES['fichero']['tmp_name'])){// verifico que haya sido cargado el archivo
$ruta= "foto/".$_FILES['fichero']['name'];
if(move_uploaded_file($_FILES['fichero']['tmp_name'],$ruta)){ //se coloca en su lugar final
echo "<b>subida exitosa!. datos:</b><br>";
echo "Nombre:<i><a href=\"foto/".$_FILES['fichero']['name']."\">".$_FILES['fichero']['name']."</a></i><br>";
echo "Tipo: <i>".$_FILES['fichero']['type']."</i><br>";
echo "Peso: <i>".$_FILES['fichero']['size']." bytes</i><br>";
echo "<br><hr><br>";
mysql_query("INSERT INTO imagenes (ruta) values ('$ruta')",$link)or die (mysql_error());
}
}
} // A continuación el formulario
?>
<form action="mostrar_foto.php" method="post" enctype="multipart/form-data"/>
<p class="Estilo1">
<label></label>
</p>
<table width="439" height="163" border="0">
<tr>
<td width="87"><span class="Estilo1">Nombre:</span></td>
<td width="201"><span class="Estilo1">
<input type="text" name="nombre" />
</span></td>
</tr>
<tr>
<td><span class="Estilo1">Subir Foto :</span></td>
<td><input name="fichero" type="file" /></td>
</tr>
<tr>
<td height="54"><span class="Estilo1">Comentario : </span></td>
<td><label>
<textarea name="comentario"></textarea>
</label></td>
</tr><tr>
<td colspan="2"><input name="submit" type="submit" value="Subir" /></td>
</tr>
</table>
</form>