Foros del Web » Programando para Internet » PHP »

problema con formulario, por favor

Estas en el tema de problema con formulario, por favor en el foro de PHP en Foros del Web. HOLA ESTOY EN BUSCA DE SU AYUDA : TENGO ESTE FORMULARIO PARA ENVIAR ARTICULOS A MI WEB ES PARA UN SITIO DE CLASIFICADOS QUE ESTOY ...
  #1 (permalink)  
Antiguo 17/10/2011, 17:10
 
Fecha de Ingreso: marzo-2011
Mensajes: 115
Antigüedad: 13 años, 1 mes
Puntos: 0
problema con formulario, por favor

HOLA ESTOY EN BUSCA DE SU AYUDA :

TENGO ESTE FORMULARIO PARA ENVIAR ARTICULOS A MI WEB ES PARA UN SITIO DE CLASIFICADOS QUE ESTOY HACIENDO MIREN ESTE ES EL SCRIPT

Código PHP:
<!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-1" />
<title>Documento sin t&iacute;tulo</title>
<style type="text/css">
<!--
#Layer1 {
    position:absolute;
    left:123px;
    top:33px;
    width:600px;
    height:600px;
    z-index:1;
}
-->
</style>
</head>

<body>
<div id="Layer1">
  <form action="<?php echo $editFormAction?>" method="post" enctype="multipart/form-data" name="form1" id="form1">
    <label for="select"></label>
    <hr />
    <label for="select">Sección : </label>
    <select name="select" id="select">
      <option value="0" selected="selected">Seleccionar</option>
      <option value="1">Compra y Venta</option>
      <option value="2">Clases</option>
    </select>
    <p>
      <label for="label">Ubicación : </label>
      <select name="select2" id="label">
        <option value="0">Seleccionar </option>
        <option value="1">Montevideo</option>
        <option value="2">Canelones</option>
      </select>
    </p>
    <hr />
    <p>
      <label for="textfield">Precio : </label>
      <input name="textfield" type="text" id="textfield" size="10" />
      <label for="label3">Moneda :</label>
      <select name="select3" id="label3">
        <option value="0">Seleccionar</option>
        <option value="1">Pesos </option>
        <option value="2">Dolar</option>
      </select>
    </p>
    <p>Titulo : 
      <label for="label4"></label>
      <input type="text" name="textfield2" id="label4" />
    </p>
    <p>Descripci&oacute;n : </p>
    <p>
      <label for="textarea"></label>
      <textarea name="content" cols="60" rows="14"></textarea>
    </p>
    <hr />
    <p>
      <label for="label5">E-mail : </label>
      <input type="text" name="textfield3" id="label5" />
      <label for="Submit">Repetir E-mail : </label>
      <label for="label6"></label>
      <input type="text" name="textfield4" id="label6" />
      <label for="Submit"><br />
      <br />
      T&eacute;lefono : </label>
      <label for="label7"></label>
      <input type="text" name="textfield5" id="label7" />
      <label for="Submit"><br />
      <br />
      </label>
      <label for="file">Imagen : </label>
      <input type="file" name="file" id="file" />
      <label for="Submit"><br />
      <br />
      </label>
      <label for="label8"></label>
      <label for="Submit"></label>
      <input type="submit" name="Submit" value="Enviar" id="Submit" />
      <label for="label2"></label>
      <input type="reset" name="Submit2" value="Restablecer" id="label2" />
    </p>
  </form>
</div>
</body>
</html>
<script language="javascript"
    type="text/javascript" src="../editor/scripts/tiny_mce.js"></script>
    </label>
    <p>
      <script language="javascript" type="text/javascript" src="../editor/scripts/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
tinyMCE.init({
    mode : "textareas",
    theme : "advanced",
    theme_advanced_buttons1 : "bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright, justifyfull,bullist,numlist,undo,redo,link,unlink",
    theme_advanced_buttons2 : "",
    theme_advanced_buttons3 : "",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    theme_advanced_path_location : "bottom",
    extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]"
});
</script> 
<?php require_once('Connections/anuncios.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"] == "form1")) {
  
$insertSQL sprintf("INSERT INTO formulario (id_rubro, seccion, ubicacion, precio, simbolo, Titulo, Descripcion, email, repetir_email, telefono, Imagen) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       
GetSQLValueString($_POST['id_rubro'], "int"),
                       
GetSQLValueString($_POST['seccion'], "select"),
                       
GetSQLValueString($_POST['ubicacion'], "select2"),
                       
GetSQLValueString($_POST['precio'], "textfield"),
                       
GetSQLValueString($_POST['simbolo'], "select3"),
                       
GetSQLValueString($_POST['Titulo'], "textfield2"),
                       
GetSQLValueString($_POST['Descripcion'], "content"),
                       
GetSQLValueString($_POST['email'], "textfield3"),
                       
GetSQLValueString($_POST['repetir_email'], "textfield4"),
                       
GetSQLValueString($_POST['telefono'], "textfield5"),
                       
GetSQLValueString($_POST['Imagen'], "file"));

  
mysql_select_db($database_anuncios$anuncios);
  
$Result1 mysql_query($insertSQL$anuncios) or die(mysql_error());

  
$insertGoTo "untitledcopia.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?";
    
$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$insertGoTo));
}
?>
lo que no logro es que lo que escribo se guarde en la base de datos y luego pueda verlos?

si alguien me puede ayudar muy agradecido....
  #2 (permalink)  
Antiguo 17/10/2011, 20:47
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Respuesta: problema con formulario, por favor

Pues el problema es muy claro, en tu formulario los elementos tienen nombres como: textfield, textfield1, textfield2, etc. y en tu código estas rescatando id_rubro, seccion, ubicacion, etc.
  #3 (permalink)  
Antiguo 18/10/2011, 09:38
 
Fecha de Ingreso: marzo-2011
Mensajes: 115
Antigüedad: 13 años, 1 mes
Puntos: 0
Respuesta: problema con formulario, por favor

OK MUCHAS GRACIAS.. YA LO SOLUCIONE TE MUESTRO LOS SCRIPT


untitled.php


Código PHP:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><style type="text/css">
  5. #apDiv1 {
  6.     position:absolute;
  7.     left:225px;
  8.     top:17px;
  9.     width:530px;
  10.     height:161px;
  11.     z-index:1;
  12. }
  13. </style>
  14. <div id="apDiv1">
  15.   <form action="/untitledcopia.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
  16.     <p>
  17.       <label for="ubicacion"></label>
  18.       Sección :
  19.       <select name="seccion" id="select2">
  20.         <option value="Seleccionar" selected="selected">Seleccionar</option>
  21. <option value="Compra y Venta">Compra y Venta</option>
  22.         <option value="Vehiculos ">Vehiculos</option>
  23.       </select>
  24.        Ubicacion :
  25.       <select name="ubicacion" id="select3">
  26.         <option value="Seleccionar">Seleccionar</option>
  27.         <option value="Montevideo">Montevideo</option>
  28.         <option value="Canelones">Canelones</option>
  29.         <option value="Maldonado">Maldonado</option>
  30.       </select>
  31.     </p>
  32.     <p>
  33.       <label for="moneda"></label>
  34.       Precio :
  35.       <input type="text" name="precio" id="textfield2" />
  36.       <label for="moneda">Moneda : </label>
  37.       <select name="moneda" id="moneda">
  38.         <option value="Seleccionar">Seleccionar</option>
  39.         <option value="Pesos">Pesos</option>
  40.         <option value="Dolares">Dolares</option>
  41.         <option value="Euros">Euros</option>
  42.       </select>
  43.     </p>
  44.     <p>
  45.       <label for="content"></label>
  46.     Descripción :</p>
  47.     <p>
  48.   <textarea name="content" id="content" cols="45" rows="10"></textarea>
  49.     </p>
  50.     <p>
  51.       <label for="textfield3"></label>
  52.       Titulo :
  53.       <label for="titulo"></label>
  54.       <input type="text" name="titulo" id="titulo" />
  55.     </p>
  56.     <p>
  57.       <label for="telefono">T&eacute;lefono</label>
  58.       :
  59.       <input type="text" name="telefono" id="telefono" />
  60.     </p>
  61.     <p>
  62.       <label for="email">Email</label>
  63. :      
  64. <input type="text" name="email" id="email" />
  65.     <label for="repetir">Repetir Email : </label>
  66.     <input type="text" name="repetir" id="repetir" />
  67.     </p>
  68.     <p>
  69.       <label for="textfield2"></label>
  70.       <label for="imagen"></label>
  71.       Imagen :
  72.       <input type="file" name="imagen" id="imagen" />
  73.     </p>
  74.     <p>
  75.       <input type="submit" name="button" id="button" value="Enviar" />
  76.       <input type="reset" name="button2" id="button2" value="Restablecer" />
  77.     </p>
  78.   </form>
  79. </div>
  80. <p>&nbsp;</p>
  81. <p>&nbsp;</p>
  82. <p>&nbsp;</p>
  83. <p>&nbsp;</p>
  84. <p>&nbsp;</p>
  85. <p>&nbsp;</p>
  86. <p>&nbsp;</p>
  87. <p>&nbsp;</p>
  88. <p>&nbsp;</p>
  89. <p>&nbsp;</p>
  90. <p>&nbsp;</p>
  91. <p>&nbsp;</p>
  92. <?php require_once('Connections/anuncios.php'); ?>
  93. <?php
  94. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  95. {
  96.   $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
  97.  
  98.   switch ($theType) {
  99.     case "text":
  100.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  101.       break;    
  102.     case "long":
  103.     case "int":
  104.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  105.       break;
  106.     case "double":
  107.       $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
  108.       break;
  109.     case "date":
  110.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  111.       break;
  112.     case "defined":
  113.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  114.       break;
  115.   }
  116.   return $theValue;
  117. }
  118.  
  119. $editFormAction = $_SERVER['PHP_SELF'];
  120. if (isset($_SERVER['QUERY_STRING'])) {
  121.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  122. }
  123.  
  124. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  125.    
  126.   $insertSQL = sprintf("INSERT INTO formulario (id_rubro, seccion, ubicacion, precio, moneda, titulo, content, email, repetir_email, telefono, imagen,) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
  127.                        GetSQLValueString($_POST['id_rubro'], "id_rubro"),
  128.                        GetSQLValueString($_POST['seccion'], "seccion"),
  129.                        GetSQLValueString($_POST['ubicacion'], "ubicacion"),
  130.                        GetSQLValueString($_POST['precio'], "precio"),
  131.                        GetSQLValueString($_POST['moneda'], "moneda"),
  132.                        GetSQLValueString($_POST['titulo'], "titulo"),
  133.                        GetSQLValueString($_POST['content'], "content"),
  134.                        GetSQLValueString($_POST['email'], "email"),
  135.                        GetSQLValueString($_POST['repetir'], "repetir"),
  136.                        GetSQLValueString($_POST['telefono'], "telefono"),
  137.                        GetSQLValueString($_POST['imagen'], "imagen"));
  138.  
  139.   mysql_select_db($database_anuncios, $anuncios);
  140.   $Result1 = mysql_query($insertSQL, $anuncios) or die(mysql_error());
  141.  
  142.   $insertGoTo = "untitledcopia.php";
  143.   if (isset($_SERVER['QUERY_STRING'])) {
  144.     $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
  145.     $insertGoTo .= $_SERVER['QUERY_STRING'];
  146.   }
  147.   header(sprintf("Location: %s", $insertGoTo));
  148. }
  149. ?>
  150.  <script language="javascript"
  151.     type="text/javascript" src="../editor/scripts/tiny_mce.js"></script>
  152.     </label>
  153.     <p>
  154.       <script language="javascript" type="text/javascript" src="../editor/scripts/tiny_mce.js"></script>
  155. <script language="javascript" type="text/javascript">
  156. tinyMCE.init({
  157.     mode : "textareas",
  158.     theme : "advanced",
  159.     theme_advanced_buttons1 : "bold,italic,underline,separator,strikethrough,justifyleft,justifycenter,justifyright, justifyfull,bullist,numlist,undo,redo,link,unlink",
  160.     theme_advanced_buttons2 : "",
  161.     theme_advanced_buttons3 : "",
  162.     theme_advanced_toolbar_location : "top",
  163.     theme_advanced_toolbar_align : "left",
  164.     theme_advanced_path_location : "bottom",
  165.     extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]"
  166. });
  167. </script>

Y untitledcopia.php


Código PHP:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  5. <table width="941" height="234" border="0">
  6.   <tr>
  7.     <td width="71">Secci&oacute;n</td>
  8.     <td width="90">Ubicacion</td>
  9.     <td width="57">Precio</td>
  10.     <td width="74">Simbolo</td>
  11.     <td width="50">Titulo</td>
  12.     <td width="106">Descripcion</td>
  13.     <td width="49">Email</td>
  14.     <td width="168">Repetir Email</td>
  15.     <td width="125">T&eacute;lefono</td>
  16.     <td width="90">Imagen</td>
  17.     <td width="15">&nbsp;</td>
  18.   </tr>
  19.   <tr>
  20.     <td><?php echo $_POST['seccion'] ?></td>
  21.     <td><?php echo $_POST['ubicacion'] ?></td>
  22.     <td><?php echo $_POST['precio'] ?></td>
  23.     <td><?php echo $_POST['moneda'] ?></td>
  24.     <td><?php echo $_POST['titulo'] ?></td>
  25.     <td><?php echo $_POST['content'] ?></td>
  26.     <td><?php echo $_POST['email'] ?></td>
  27.     <td><?php echo $_POST['repetir'] ?></td>
  28.     <td><?php echo $_POST['telefono'] ?></td>
  29.     <td><?php echo $_POST['imagen'] ?></td>
  30.   </tr>
  31. </table>

LO QUE NO PUEDO LOGRAR ES VER LA IMAGEN QUE SUBO? SERA QUE ME FALTA PONER ALGO EN EL PRIMER SCRIPT?
  #4 (permalink)  
Antiguo 18/10/2011, 10:04
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Respuesta: problema con formulario, por favor

Necesitas subir la imagen al servidor, te dejo dos referencias:

http://emilio.aesinformatica.com/200...magen-con-php/
http://www.php.net/manual/es/features.file-upload.php

Saludos.
  #5 (permalink)  
Antiguo 18/10/2011, 11:09
 
Fecha de Ingreso: marzo-2011
Mensajes: 115
Antigüedad: 13 años, 1 mes
Puntos: 0
Respuesta: problema con formulario, por favor

no eh logrado hacerlo... por favor ayuda!!!

no se como hacerloooooo
  #6 (permalink)  
Antiguo 18/10/2011, 14:37
 
Fecha de Ingreso: marzo-2011
Mensajes: 115
Antigüedad: 13 años, 1 mes
Puntos: 0
Respuesta: problema con formulario, por favor

hola alguien me puede dar una ayuda ? estamos en un foro que es para eso no?

eh leido todo lo que encuentro en el santo google pero no eh logrado resultados...

lo que estoy intentando hacer en que mis usuarios puedan subir fotos a la pagina y que las fotos que ellos suban se puedan ver?

pero no lo eh logrado. aunque sea un buen tutorial que explique paso a paso como se hace?

muchas gracias a los que respondan..
  #7 (permalink)  
Antiguo 18/10/2011, 14:45
Avatar de CesarHC  
Fecha de Ingreso: junio-2011
Ubicación: localhost
Mensajes: 566
Antigüedad: 12 años, 10 meses
Puntos: 56
Respuesta: problema con formulario, por favor

El foro es para ayudarnos unos a otros, pero uno es libre de responder o no si asi lo desea.

Este es un ejemplo muy simple de como subir imagenes a un servidor espero que te ayude.

Tambien le la respuesta de GatorV con eso deberia ser suficiente para que logres lo que quieres.
__________________
Solo la práctica no te traicionara ¡¡¡¡¡¡

Seguir el camino tu debes PHP The Right Way.
  #8 (permalink)  
Antiguo 19/10/2011, 07:30
 
Fecha de Ingreso: marzo-2011
Mensajes: 115
Antigüedad: 13 años, 1 mes
Puntos: 0
Respuesta: problema con formulario, por favor

hola CesarHC gracias por tu ejemplo.

miren ahora eh logrado subir la imagen, pero a la hora de ver no me aparece les dejo los script para ver si alguien se da cuenta en que fallo. y tambien para alguna otra persona que le sirva.

esta es la base de datos :

Código MySQL:
Ver original
  1. CREATE TABLE IF NOT EXISTS `formulario` (
  2.   `id_rubro` int(11) NOT NULL AUTO_INCREMENT,
  3.   `seccion` varchar(255) NOT NULL,
  4.   `ubicacion` varchar(255) NOT NULL,
  5.   `precio` varchar(255) NOT NULL,
  6.   `simbolo` varchar(255) NOT NULL,
  7.   `Titulo` varchar(255) NOT NULL,
  8.   `Descripcion` varchar(255) NOT NULL,
  9.   `email` varchar(255) NOT NULL,
  10.   `telefono` varchar(255) NOT NULL,
  11.   `Imagen` varchar(255) NOT NULL,
  12.   PRIMARY KEY (`id_rubro`)

esta es la pagina de formulario.php

Código PHP:
Ver original
  1. <?php virtual('/Connections/anuncios.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6.   if (PHP_VERSION < 6) {
  7.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8.   }
  9.  
  10.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  11.  
  12.   switch ($theType) {
  13.     case "text":
  14.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  15.       break;    
  16.     case "long":
  17.     case "int":
  18.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  19.       break;
  20.     case "double":
  21.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  22.       break;
  23.     case "date":
  24.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  25.       break;
  26.     case "defined":
  27.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  28.       break;
  29.   }
  30.   return $theValue;
  31. }
  32. }
  33.  
  34. $editFormAction = $_SERVER['PHP_SELF'];
  35. if (isset($_SERVER['QUERY_STRING'])) {
  36.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  37. }
  38.  
  39. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  40.         $tipo_prod = $_POST["MM_insert"];
  41.  
  42.     //Guardar imagen
  43.     if(is_uploaded_file($_FILES['fleImagen']['tmp_name'])) { // verifica haya sido cargado el archivo
  44.     $ruta= "/images/$tipo_prod/".$_FILES['fleImagen']['name'];
  45.     move_uploaded_file($_FILES['fleImagen']['tmp_name'], $ruta);
  46.     }
  47.   $insertSQL = sprintf("INSERT INTO formulario (id_rubro, seccion, ubicacion, precio, simbolo, Titulo, Descripcion, email, telefono, Imagen) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
  48.                        GetSQLValueString($_POST['id_rubro'], "int"),
  49.                        GetSQLValueString($_POST['txtseccion'], "text"),
  50.                        GetSQLValueString($_POST['txtubicacion'], "text"),
  51.                        GetSQLValueString($_POST['txtprecio'], "text"),
  52.                        GetSQLValueString($_POST['txtSimbolo'], "text"),
  53.                        GetSQLValueString($_POST['txtTitulo'], "text"),
  54.                        GetSQLValueString($_POST['txtDescripcion'], "text"),
  55.                        GetSQLValueString($_POST['txtemail'], "text"),
  56.                        GetSQLValueString($_POST['txttelefono'], "text"),
  57.                        GetSQLValueString($ruta, "text"));
  58.  
  59.   mysql_select_db($database_anuncios, $anuncios);
  60.   $Result1 = mysql_query($insertSQL, $anuncios) or die(mysql_error());
  61.  
  62.   $insertGoTo = "/ingreso_exitoso.php";
  63.   if (isset($_SERVER['QUERY_STRING'])) {
  64.     $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
  65.     $insertGoTo .= $_SERVER['QUERY_STRING'];
  66.   }
  67.   header(sprintf("Location: %s", $insertGoTo));
  68. }
  69.  
  70. ?>
  71.  
  72. <form action="catalogo.php" method="POST" enctype="multipart/form-data" name="form1">
  73.   <table align="center">
  74.     <tr valign="baseline">
  75.       <td nowrap align="right">Seccion:</td>
  76.       <td><select name="txtseccion" id="txtseccion">
  77.         <option value="Seleccionar" selected>Seleccionar</option>
  78.         <option value="Accesorios">Accesorios</option>
  79.         <option value="Camisetas">Camisetas</option>
  80.       </select></td>
  81.     </tr>
  82.     <tr valign="baseline">
  83.       <td nowrap align="right">Ubicacion:</td>
  84.       <td><select name="txtubicacion" id="txtubicacion">
  85.         <option value="Seleccionar">Seleccionar</option>
  86.         <option value="Montevideo">Montevideo</option>
  87.         <option value="Maldonado">Maldonado</option>
  88.       </select></td>
  89.     </tr>
  90.     <tr valign="baseline">
  91.       <td nowrap align="right">Precio:</td>
  92.       <td><input name="txtprecio" type="text" id="txtprecio" value="" size="32"></td>
  93.     </tr>
  94.     <tr valign="baseline">
  95.       <td nowrap align="right">Moneda:</td>
  96.       <td><select name="txtsimbolo" id="txtsimbolo">
  97.         <option value="Seleccionar">Seleccionar</option>
  98.         <option value="Pesos">Pesos</option>
  99.         <option value="Dolares">Dolares</option>
  100.       </select></td>
  101.     </tr>
  102.     <tr valign="baseline">
  103.       <td nowrap align="right">Titulo:</td>
  104.       <td><input name="txtTitulo" type="text" id="txtTitulo" value="" size="32"></td>
  105.     </tr>
  106.     <tr valign="baseline">
  107.       <td nowrap align="right" valign="top">Descripcion:</td>
  108.       <td><textarea name="txtDescripcion" cols="50" rows="5" id="txtDescripcion"></textarea></td>
  109.     </tr>
  110.     <tr valign="baseline">
  111.       <td nowrap align="right">Email:</td>
  112.       <td><input name="txtemail" type="text" id="txtemail" value="" size="32"></td>
  113.     </tr>
  114.     <tr valign="baseline">
  115.       <td nowrap align="right">Telefono:</td>
  116.       <td><input name="txttelefono" type="text" id="txttelefono" value="" size="32"></td>
  117.     </tr>
  118.     <tr valign="baseline">
  119.       <td nowrap align="right">Imagen:</td>
  120.       <td><input name="fleImagen" type="file" id="fleImagen" value="" size="32" /></td>
  121.     </tr>
  122.     <tr valign="baseline">
  123.       <td nowrap align="right">&nbsp;</td>
  124.       <td><input type="submit" value="Insertar registro"> <input type="reset" name="button" id="button" value="Restablecer"></td>
  125.     </tr>
  126.   </table>
  127.   <input type="hidden" name="id_rubro" value="">
  128.   <input type="hidden" name="MM_insert" value="form1">
  129. </form>
  130. <p>&nbsp;</p>

y esta es la de catalogo.php

Código PHP:
Ver original
  1. <?php virtual('/Connections/anuncios.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6.   if (PHP_VERSION < 6) {
  7.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8.   }
  9.  
  10.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  11.  
  12.   switch ($theType) {
  13.     case "text":
  14.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  15.       break;    
  16.     case "long":
  17.     case "int":
  18.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  19.       break;
  20.     case "double":
  21.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  22.       break;
  23.     case "date":
  24.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  25.       break;
  26.     case "defined":
  27.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  28.       break;
  29.   }
  30.   return $theValue;
  31. }
  32. }
  33.  
  34. $maxRows_catalogo_imag = 10;
  35. $pageNum_catalogo_imag = 0;
  36. if (isset($_GET['pageNum_catalogo_imag'])) {
  37.   $pageNum_catalogo_imag = $_GET['pageNum_catalogo_imag'];
  38. }
  39. $startRow_catalogo_imag = $pageNum_catalogo_imag * $maxRows_catalogo_imag;
  40.  
  41. mysql_select_db($database_anuncios, $anuncios);
  42. $query_catalogo_imag = "SELECT * FROM formulario";
  43. $query_limit_catalogo_imag = sprintf("%s LIMIT %d, %d", $query_catalogo_imag, $startRow_catalogo_imag, $maxRows_catalogo_imag);
  44. $catalogo_imag = mysql_query($query_limit_catalogo_imag, $anuncios) or die(mysql_error());
  45. $row_catalogo_imag = mysql_fetch_assoc($catalogo_imag);
  46.  
  47. if (isset($_GET['totalRows_catalogo_imag'])) {
  48.   $totalRows_catalogo_imag = $_GET['totalRows_catalogo_imag'];
  49. } else {
  50.   $all_catalogo_imag = mysql_query($query_catalogo_imag);
  51.   $totalRows_catalogo_imag = mysql_num_rows($all_catalogo_imag);
  52. }
  53. $totalPages_catalogo_imag = ceil($totalRows_catalogo_imag/$maxRows_catalogo_imag)-1;
  54. ?>
  55. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  56. <html xmlns="http://www.w3.org/1999/xhtml">
  57. <head>
  58. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  59. <title>Documento sin título</title>
  60. </head>
  61.  
  62. <body>
  63. <table border="0">
  64.   <tr>
  65.     <td>id_rubro</td>
  66.     <td>seccion</td>
  67.     <td>ubicacion</td>
  68.     <td>precio</td>
  69.     <td>simbolo</td>
  70.     <td>Titulo</td>
  71.     <td>Descripcion</td>
  72.     <td>email</td>
  73.     <td>telefono</td>
  74.     <td>Imagen</td>
  75.   </tr>
  76.   <?php do { ?>
  77.     <tr>
  78.       <td><?php echo $row_catalogo_imag['id_rubro']; ?></td>
  79.       <td><?php echo $row_catalogo_imag['seccion']; ?></td>
  80.       <td><?php echo $row_catalogo_imag['ubicacion']; ?></td>
  81.       <td><?php echo $row_catalogo_imag['precio']; ?></td>
  82.       <td><img "<?php echo $row_catalogo_imag['Imagen']; ?> " /></td>    
  83.       <td><?php echo $row_catalogo_imag['Titulo']; ?></td>
  84.       <td><?php echo $row_catalogo_imag['Descripcion']; ?></td>
  85.       <td><?php echo $row_catalogo_imag['email']; ?></td>
  86.       <td><?php echo $row_catalogo_imag['telefono']; ?></td>
  87.       <td><?php echo $row_catalogo_imag['simbolo']; ?> </td>
  88.     </tr>
  89.     <?php } while ($row_catalogo_imag = mysql_fetch_assoc($catalogo_imag)); ?>
  90. </table>
  91. </body>
  92. </html>
  93. <?php
  94. mysql_free_result($catalogo_imag);
  95. ?>
  96. <img src=" " />

yo no me doy cuenta pero si alguien lo ve desde ya muchas gracias!!!
  #9 (permalink)  
Antiguo 19/10/2011, 07:44
Avatar de CesarHC  
Fecha de Ingreso: junio-2011
Ubicación: localhost
Mensajes: 566
Antigüedad: 12 años, 10 meses
Puntos: 56
Respuesta: problema con formulario, por favor

Le he dado una hojeada y no veo que guardes la url de la imagen que guardas, solo veo la ruta en que la guardas.

Tendrias que tener en tu bd un campo mas llamado digamos "url" en donde guardes la ruta en que esta la imagen y se pueda ver en el navegador.

Algo asi seria.

Código PHP:
Ver original
  1. $ruta_destino = "http://localhost/miproyecto/fotos/";
  2.         $namefinal= trim ($_FILES['fichero']['name']);
  3.     $url= $ruta_destino . $namefinal;
__________________
Solo la práctica no te traicionara ¡¡¡¡¡¡

Seguir el camino tu debes PHP The Right Way.
  #10 (permalink)  
Antiguo 19/10/2011, 08:04
 
Fecha de Ingreso: marzo-2011
Mensajes: 115
Antigüedad: 13 años, 1 mes
Puntos: 0
De acuerdo Respuesta: problema con formulario, por favor

Cita:
Iniciado por CesarHC Ver Mensaje
Le he dado una hojeada y no veo que guardes la url de la imagen que guardas, solo veo la ruta en que la guardas.

Tendrias que tener en tu bd un campo mas llamado digamos "url" en donde guardes la ruta en que esta la imagen y se pueda ver en el navegador.

Algo asi seria.

Código PHP:
Ver original
  1. $ruta_destino = "http://localhost/miproyecto/fotos/";
  2.         $namefinal= trim ($_FILES['fichero']['name']);
  3.     $url= $ruta_destino . $namefinal;
ajja gracias por responder.

puedo hacer otra pregunta?

mira, me dices que necesito en la base de datos otro campo, pero este campo tendria que ser varchar, int u otro ?

y ese fragmento de script que me diste iria en la parte de formulario verdad

yo lo puse asi :

Código PHP:
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
        
$tipo_prod $_POST["MM_insert"];

    
//Guardar imagen
    
if(is_uploaded_file($_FILES['fleImagen']['tmp_name'])) { // verifica haya sido cargado el archivo
    
$ruta"/images/$tipo_prod/".$_FILES['fleImagen']['name'];
    
move_uploaded_file($_FILES['fleImagen']['tmp_name'], $ruta);  
      
$ruta_destino "http://localhost/images/";
            
$namefinaltrim ($_FILES['fichero']['name']);
        
$url$ruta_destino $namefinal
bueno disculpa mi ignorancia.
  #11 (permalink)  
Antiguo 19/10/2011, 08:09
Avatar de CesarHC  
Fecha de Ingreso: junio-2011
Ubicación: localhost
Mensajes: 566
Antigüedad: 12 años, 10 meses
Puntos: 56
Respuesta: problema con formulario, por favor

Deberias usar varchar ponle un valor suficientemente largo para las urls, sobre el fragmento de codigo esta bien puesto hay pero en la ruta debe ser.

http://localhost/tuproyecto/images/

y no

http://localhost/images/
__________________
Solo la práctica no te traicionara ¡¡¡¡¡¡

Seguir el camino tu debes PHP The Right Way.
  #12 (permalink)  
Antiguo 19/10/2011, 08:17
 
Fecha de Ingreso: marzo-2011
Mensajes: 115
Antigüedad: 13 años, 1 mes
Puntos: 0
Respuesta: problema con formulario, por favor

Cita:
Iniciado por CesarHC Ver Mensaje
Deberias usar varchar ponle un valor suficientemente largo para las urls, sobre el fragmento de codigo esta bien puesto hay pero en la ruta debe ser.

[url]http://localhost/tuproyecto/images/[/url]

y no

[url]http://localhost/images/[/url]
ok gracias le puse valor 255

Etiquetas: favor, formulario, html, mysql, sql
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 07:44.