Les ruego encarecidamente, por favor, ayúdenme con este formulario que me tiene loco. Trato de publicar una noticia y logro inyectar la data correctamente a la base de datos MySQL, con categoría y todo, lo cual mi formulario hace sin problemas; funciona como relojito. Pero cuando trato que el nombre de la foto quede almacenada en el campo 'notFoto' no pasa nada. Estoy usando un campo varchar 255, para almacenar el nombre de la foto, no me gustan los campos BLOB (de hecho, no tengo pensado hacerlo, me carga esta solución, así es que, porfa, no me lo aconsejen! jeje).
Dentro del formulario está la programación para subir una foto, de hecho lo hace, queda en la carpeta seleccionada para tales efectos, pero -repito- el nombre de la foto no queda registrado en la BDD. Tengo listo el index.php en la parte del frontpage para mostrar la noticia publicada y funciona de lo más bien, cero problemas. pero no hay foto ... la base de datos (reitero) no contiene el nombre de la foto en el campo $notFoto y, por lo tanto, muestra la clásica x de que ... no hay foto!!


Estoy ya rayado con esto, a punto de pegarme un tiro poco menos ... ¿qué estoy haciendo mal????
Acá va el formulario:
Código PHP:
<?php
// incluimos el archivo de conexion
include ('db-cnx.php');
// recibimos el formulario
if(isset($_POST['enviar']) && $_POST['enviar'] == 'Enviar'){
// comprobamos que el formulario no envie campos vacios
if(!empty($_POST['notTitulo']) && $_POST['notTexto'] && $_POST['catCategoria'] && $_POST['fecha']){
// creamos las variables y les asignamos los valores a insertar
$notTitulo = $_POST['notTitulo'];
$notTexto = $_POST['notTexto'];
$notFoto = $_POST['notFoto'];
$fecha = $_POST['fecha'];
$catCategoria = $_POST['catCategoria'];
// hacemos el INSERT en la BD
$sqlInsertNot = mysql_query("INSERT INTO sn_noticias
(notTitulo, notTexto, notFoto, catCategoria, fecha)
VALUES ('$notTitulo', '$notTexto','$notFoto', '$catCategoria', '$fecha')",
$db_link) or die(mysql_error());
// enviamos un mensaje de exito
echo "<b>Los datos fueron guardados correctamente</b> | <a href=\"index.php\">Volver a la Administración</a>";
}else{
// si el formulario envia algun campo vacio
// enviamos un mensaje de error
echo "Debe llenar todos los campos del formulario<br />";
}
}
//Subimos le imagen a la carpeta, en este caso "fotos"
if (isset($_POST['enviar'])) {
if(is_uploaded_file($_FILES['notFoto']['tmp_name'])) { // verifica haya sido cargado el archivo
$ruta= "../fotos/".$_FILES['notFoto']['name']; // Se guardaría dentro de "fotos" con el nombre original
// $ruta= "carpeta/nuevo_nombre.jpg"; si también se quiere renombrar
move_uploaded_file($_FILES['notFoto']['tmp_name'], $ruta);
if(move_uploaded_file($_FILES['notFoto']['tmp_name'], $_FILES['notFoto']['name'])) { // se coloca en su lugar final
echo "<b>Upload exitoso!. Datos:</b><br>";
echo "Nombre: <i><a href=\"".$_FILES['notFoto']['name']."\">".$_FILES['notFoto']['name']."</a></i><br>";
echo "Tipo MIME: <i>".$_FILES['notFoto']['type']."</i><br>";
echo "Peso: <i>".$_FILES['notFoto']['size']." bytes</i><br>";
echo "<br><hr><br>";
}
}
// A continuación el formulario
}
?>
<!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=iso-8859-2" />
<title>Agregar Noticia</title>
<LINK HREF="style.css" REL="stylesheet" TYPE="text/css">
<script type="text/javascript" src="jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
// General options
mode : "textareas",
theme : "advanced",
plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
// Theme options
theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
// Example content CSS (should be your site CSS)
content_css : "css/content.css",
// Drop lists for link/image/media/template dialogs
template_external_list_url : "lists/template_list.js",
external_link_list_url : "lists/link_list.js",
external_image_list_url : "lists/image_list.js",
media_external_list_url : "lists/media_list.js",
// Replace values for the template plugin
template_replace_values : {
username : "Some User",
staffid : "991234"
}
});
</script>
<!-- /TinyMCE -->
<style type="text/css">
<!--
@import url("css-add-noti.css");
body {
margin-left: 20px;
margin-top: 15px;
}
-->
</style>
</head>
<body text="#17334a" vlink="#000040" alink="#000040" link="#000040" bgcolor="#ffffff" background="images/index_bg.gif">
<div class="ts-1">
<!-- el formulario -->
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" name="noticia">
<p>Agregar las noticias preferible en formato HTML </p>
<p>Título de la Noticia<br />
<input type="text" name="notTitulo" size="70" />
</p>
<p>
Texto de la Noticia<br />
<textarea name="notTexto" rows="20" cols="90"></textarea>
<br />
<input name="fecha" type="hidden" value="<?=date("Y-m-d"); ?> <?=date("h:i:s");?>" />
<br />
<label>
<input type="file" name="notFoto" id="notFoto" />
</label>
<br />
</p>
<p>
Categoría<br />
<select name="catCategoria">
<option value="">Escoger de la Lista</option>
<?php
// asignamos una categoria a la noticia
// mediante un select
$sqlQueryCat = mysql_query("SELECT * FROM sn_categorias", $db_link)
or die(mysql_error);
// creamos un bucle while
// que nos muestre todas las categorias
// que tenemos guardadas en la BD
while($rowCat = mysql_fetch_array($sqlQueryCat)){ ?>
<!-- echo "<option value='$rowCat[cat_ID]'>$rowCat[catCategoria] - $rowCat[cat_ID]</option>";-->
<option value='<?=$rowCat[catCategoria]; ?>'><?=$rowCat[catCategoria]; ?></option>
<? } ?>
</select>
<br />
<br />
<input type="submit" name="enviar" value="Enviar" />
</form>
</body>
</html>