Comunidad de diseño web y desarrollo en internet online

ERROR al cargar imagen en registro

Citar            
MensajeEscrito el 11 Mar 2010 05:46 pm
tengo un formulario para insertar registros a mi BD , y todo funciona bien salvo a la hora de cargar la imagen
http://foros.cristalab.com/posting.php?mode=newtopic&f=18#

me sale este notice

Notice: Undefined index: imagen1 in E:\Archivos de programa\EasyPHP-5.3.1\www\argentina\gestion\nuevoregistro2.php on line 44
La imagen 24oobgm.jpg fue correctamente cargada!La columna 'imagen' no puede ser nula


les dejo el codigo muchas gracias

<?php require_once('../Connections/argentina.php'); ?>
<?php






function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}


if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "formulario")) {
$insertSQL = sprintf("INSERT INTO obras1 (titulo, subtitulo, imagen, texto, fecha, descripcion) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['textfield'], "text"),
GetSQLValueString($_POST['textfield2'], "text"),
GetSQLValueString($_POST['imagen1'], "text"),
GetSQLValueString($_POST['textarea'], "text"),
GetSQLValueString($_POST['textfield3'], "date"),
GetSQLValueString($_POST['textarea2'], "text"));

if (is_uploaded_file($_FILES['imagen1']['tmp_name'])) {
move_uploaded_file($_FILES['imagen1']['tmp_name'], "../fotos/" . $_FILES['imagen1']['name']);
echo 'La imagen '; echo $_FILES['imagen1']['name']. ' fue correctamente cargada!';
}

mysql_select_db($database_argentina, $argentina);
$Result1 = mysql_query($insertSQL, $argentina) or die(mysql_error());
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);


}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Documento sin t&iacute;tulo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
background-color: #00446C;
}
.Estilo1 { font-size: 18px;
font-weight: bold;
}
.estilotextarea {width:400px;height:100px;border: 2px solid ;}
.estilotextarea2 {width:400px;height:20px;border: 2px solid ;}
-->
</style></head>

<body>
<div align="center">
<p><img src="../argtrab.png" width="745" height="266">
</p>
<p>&nbsp;</p>
<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="formulario" id="formulario">
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<table width="448" border="1">
<tr>
<td width="92">&nbsp;</td>
<td width="340"><input type="text" name="textfield"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="text" name="textfield2"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><textarea name="textarea"></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name="imagen1" type="file" id="imagen1"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><textarea name="textarea2"></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name="textfield3" type="text" id="textfield3"></td>
</tr>
</table>
<p>
<input type="submit" name="Submit" value="Enviar">
</p>
<input type="hidden" name="MM_insert" value="formulario">
</form>
<p>&nbsp;</p>
<p>&nbsp; </p>
</div>
</body>
</html>

Por Cosmik

5 de clabLevel



 

firefox
Citar            
MensajeEscrito el 11 Mar 2010 07:50 pm
Hace un

Código PHP :

 print_r($_FILES);exit;


y chequea que el indice que buscas imagen1 exista

Por pablofmorales

Claber

103 de clabLevel

1 tutorial

Genero:Masculino  

Web developer

firefox
Citar            
MensajeEscrito el 12 Mar 2010 05:53 pm
lo que me devuelve

array(0) { }

Por Cosmik

5 de clabLevel



 

firefox
Citar            
MensajeEscrito el 12 Mar 2010 05:54 pm
ahi esta. No estas pasando bien el archivo.

Revisa tu formulario, y las variables que estas usando.

Por pablofmorales

Claber

103 de clabLevel

1 tutorial

Genero:Masculino  

Web developer

firefox
Citar            
MensajeEscrito el 12 Mar 2010 08:01 pm
me toma la variable como nula

Notice: Undefined index: imagen in E:\Archivos de programa\EasyPHP-5.3.1\www\argentina\gestion\nuevoregistro2.php on line 47
INSERT INTO obras1 (titulo, subtitulo, imagen, texto, fecha, descripcion) VALUES (''sdad'', ''sad'', 'NULL', ''dsadas'', 'dsa', ''dsa'')La imagen 13.jpg fue correctamente cargada!Algo está equivocado en su sintax cerca 'sdad'', ''sad'', 'NULL', ''dsadas'', 'dsa', ''dsa'')' en la linea 1

Por Cosmik

5 de clabLevel



 

firefox
Citar            
MensajeEscrito el 12 Mar 2010 11:33 pm
pude corregirlo poniento esto
GetSQLValueString($_FILES['imagen']['name'], "text"),
mi problema ahora es que tengo las imagenes dentro de una carpeta llamada fotos como hago para que cargue de esa carpeta , igualmente muchas gracias por tu ayuda

Por Cosmik

5 de clabLevel



 

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.