Foros del Web » Programando para Internet » PHP »

Consulta sobre $_file y GetSQLValueString

Estas en el tema de Consulta sobre $_file y GetSQLValueString en el foro de PHP en Foros del Web. Hola buenos dias tengo un formulario de insersion de registros,,con varios campos y uno para cargar imagen a mi carpeta "fotos" pero no me carga ...
  #1 (permalink)  
Antiguo 11/03/2010, 09:12
 
Fecha de Ingreso: marzo-2010
Mensajes: 4
Antigüedad: 14 años, 1 mes
Puntos: 0
Pregunta

Hola buenos dias
tengo un formulario de insersion de registros,,con varios campos y uno para cargar imagen a mi carpeta "fotos" pero no me carga en la base de dattos


el tema es que me carga en un registro solamente la foto y en otro me carga los demas campos que puedo modificar para que me cargue todo en un mismo registro ,,estube probando varias formas pero no puedo encontrar la solucion muchas gracias!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!


Código PHP:
<?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="http://www.forosdelweb.com/f18/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>
me sale este error
Notice: Undefined index: imagen1 in E:\Archivos de programa\EasyPHP-5.3.1\www\argentina\gestion\nuevoregistro2.php on line 44
La imagen 1.jpg fue correctamente cargada!La columna 'imagen' no puede ser nula

Última edición por COsmik; 11/03/2010 a las 11:59 Razón: mas info
  #2 (permalink)  
Antiguo 11/03/2010, 10:00
Avatar de eulloa  
Fecha de Ingreso: octubre-2007
Ubicación: Donde caiga la noche, si mi hijo me deja
Mensajes: 691
Antigüedad: 16 años, 6 meses
Puntos: 5
Respuesta: Consulta sobre $_file y GetSQLValueString

Lo q te está diciendo es q el valor no está llegando a la BD, haz un var_dump a la variable antes de intentar insertar a la BD
  #3 (permalink)  
Antiguo 11/03/2010, 10:08
 
Fecha de Ingreso: marzo-2010
Mensajes: 4
Antigüedad: 14 años, 1 mes
Puntos: 0
colocando var_dump ($_FILES); en el comienzo de mi codigo me devuelve

rray(1) { ["imagen1"]=> array(5) { ["name"]=> string(20) "1-kirchner-local.jpg" ["type"]=> string(10) "image/jpeg" ["tmp_name"]=> string(52) "E:\Archivos de programa\EasyPHP-5.3.1\tmp\php46A.tmp" ["error"]=> int(0) ["size"]=> int(111381) } }
Notice: Undefined index: imagen1 in E:\Archivos de programa\EasyPHP-5.3.1\www\argentina\gestion\nuevoregistro2.php on line 45
La imagen 1-kirchner-local.jpg fue correctamente cargada!La columna 'imagen' no puede ser nula

Última edición por COsmik; 11/03/2010 a las 12:01 Razón: mas info

Etiquetas: mysql
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:46.