Mi problema viene del famoso envio de noticias con upload de imagen. Despues de varias horas logre que me guarde la imagen en una carpeta y que me suba la info a la BD al mismo tiempo. El problema es solo uno: no logro q me guarde la direccion de la imagen en la celda de la tabla, simplemente queda vacia y no se si es problema de creacion de tabla o de mi codigo.
El query de la tabla:
Código:
El formulario:create table ENTREVISTA ( ID int(10) NOT NULL auto_increment, TITULO varchar(100) NOT NULL, CABECERA longtext NOT NULL, TEXTO longtext NOT NULL, FOTO varchar(100) NULL default '', primary key (ID) );
Código HTML:
<html> <head> <title>xxxxxxxxx</title> <link rel="stylesheet" type="text/css" href="Template041.css"> </head> <body leftmargin="0" topmargin="0"> <div align="center"> <table cellpadding="0" cellspacing="0" width="756" class="Middle"> <tr> <td><img src="images/TopBar1.gif" width="13" height="16"></td> <td class="TopBar" width="100%"></td> <td><img src="images/TopBar2.gif" width="11" height="16"></td> </tr> </table> <table cellpadding="0" cellspacing="0" width="752" class="Middle Dark"> <tr> <td><div align="center"></div></td> <td width="100%" valign="top"> <p class="FirstBreakBefore"> <div align="center"> <p><font size="5">Ingreso de Entrevistas</font></p> <form action="creaentrevista.php" method="POST" enctype="multipart/form-data" name="formentre" id="formentre"> <table width="600" bordercolor="#252525" bgcolor="#999999"> <tr> <td width="102" valign="top"><font size="2">Título:</font></td> <td width="486"><input name="TITULO" type="text" id="TITULO" size="81"></td> </tr> <tr> <td valign="top"><font size="2">Cabecera:</font></td> <td><textarea name="CABECERA" cols="75" rows="5" wrap="VIRTUAL" id="CABECERA"></textarea></td> </tr> <tr> <td valign="top"><font size="2">Texto:</font></td> <td><textarea name="TEXTO" cols="75" rows="20" wrap="VIRTUAL" id="TEXTO"></textarea></td> </tr> <tr> <td valign="top"><font size="2">Imagen 1:</font></td> <td><input name="FOTO" type="file" id="FOTO" style="float: left" size="50"></td> </tr> </table> <p> </p> <p> <input type="submit" name="Submit" value="Enviar"> <input type="reset" name="Submit2" value="Restablecer"> <input type="hidden" name="MAX_FILE_SIZE" value="100000"> </p> </form> <p><br> </p> </div></td> <td><p> </p> <p> </p></td> </tr> </table> <table cellpadding="0" cellspacing="0" width="752" class="Bottom"> <tr> <td><img src="imagenes/footer.jpg" width="750" height="24"></td> </tr> </table> </div> </body> </html>
Código PHP:
<?php
/*****Creado por: [email protected]*****/
/* ginitofl */
/* Gino Flores Lopez */
$server="xxxxxx"; /* Nuestro server mysql: */
$database="xxxxxxxxxxx"; /* Nuestra base de datos */
$dbpass="xxxxxxxxxx"; /*Nuestro password */
$dbuser="xxxxxxxxxxx"; /* Nuestro user */
//datos del arhivo
$texto = trim($_POST['TEXTO']);
$cabecera = trim($_POST['CABECERA']);
$titulo = trim($_POST['TITULO']);
$foto = trim($_POST['FOTO']);
$nombre_archivo = $HTTP_POST_FILES["FOTO"]["name"];
$tipo_archivo = $HTTP_POST_FILES["FOTO"]["type"];
$tamano_archivo = $HTTP_POST_FILES["FOTO"]["size"];
//compruebo si las características del archivo son las que deseo
if (!((strpos($tipo_archivo, "gif") || strpos($tipo_archivo, "jpeg")) && ( $tamano_archivo < 100000)))
{
echo "La extensión o el tamaño de los archivos no es correcta. <br><br><table><tr><td><li>Se permiten archivos .gif o .jpg<br><li>se permiten archivos de 100 Kb máximo.</td></tr></table>";
?>
<script language="javascript">
setTimeout("url()",3000);
function url()
{
window.history.back();
}
</script>
<?php
}
else
{
$nom_img= $nombre_archivo;
$directorio = 'fotos/';
if (move_uploaded_file($HTTP_POST_FILES['FOTO']['tmp_name'],$directorio . "/" . $nom_img))
{
$diaactual= date("d");
$mesactual= date("m");
$anoactual= date("Y");
$fecha= $diaactual . "/" . $mesactual . "/" . $anoactual;
//NOS CONECTAMOS A LA BASE DE DATOS
$link=mysql_connect($server,$dbuser,$dbpass);
$query="INSERT INTO entrevista (TITULO,CABECERA,TEXTO,FOTO) VALUES ('$titulo','$cabecera','$texto','$foto')";
$result=mysql_db_query($database,$query,$link);
if(mysql_affected_rows($link))
{
echo "Noticia ingresada correctamente";
} else
{
echo "Error introduciendo la Noticia";
} /* Cierre del else */
}
else
{
echo "error al subir la foto";
}
}
?>
Alguien podria ayudarme con ese simple problema ???
Gracias de antemano.
EDIT: YA ESTA SOLUCIONADO, GRACIAS IGUALMENTE