Foros del Web » Programando para Internet » PHP »

Cargar campo de BD en textarea

Estas en el tema de Cargar campo de BD en textarea en el foro de PHP en Foros del Web. Hola, tengo el formulario: Código PHP: ... <tr height="25">   <td><br />EQUIPAMIENTO </td>   <td>      <textarea name="equipamiento" id="equipamiento" value=" <?php  echo  $vehiculo -> equipamiento ?> "rows="2" cols="44"> </textarea>   </td>  </tr> ... ¡¡No me carga el ...
  #1 (permalink)  
Antiguo 02/03/2012, 01:38
 
Fecha de Ingreso: enero-2012
Mensajes: 52
Antigüedad: 12 años, 2 meses
Puntos: 1
Exclamación Cargar campo de BD en textarea

Hola, tengo el formulario:
Código PHP:
...
<tr height="25">
  <td><br />EQUIPAMIENTO </td>
  <td>
  
  <textarea name="equipamiento" id="equipamiento" value="<?php echo $vehiculo->equipamiento ?>"rows="2" cols="44"> </textarea>
  </td>
 </tr>
...
¡¡No me carga el valor del campo de la BD!!.Por favor help me!!!
  #2 (permalink)  
Antiguo 02/03/2012, 01:41
Avatar de repara2  
Fecha de Ingreso: septiembre-2010
Ubicación: München
Mensajes: 2.445
Antigüedad: 13 años, 7 meses
Puntos: 331
Respuesta: Cargar campo de BD en textarea

Con el código que posteas es imposible ayudarte, además tampoco se entiende la pregunta. Postea por lo menos, el formulario y el script que lo procesa. Saludos
__________________
Fere libenter homines, id quod volunt, credunt.
  #3 (permalink)  
Antiguo 02/03/2012, 01:56
 
Fecha de Ingreso: enero-2012
Mensajes: 52
Antigüedad: 12 años, 2 meses
Puntos: 1
Exclamación Respuesta: Cargar campo de BD en textarea

El formulario:
Código PHP:
<form  name="mantenimiento" action="mantenimientoCode.php" enctype="text/plain">
 <table border="0" style="left:45px;">
  <tr height="25">
   <td>MARCA </td>
   <td> 
 <input type="text" name="marca"  id="marca" size="18" maxlength="18" value="<?php echo $vehiculo->marca ?>">
   </td>
 </tr>
 <tr height="25">
  <td>MODELO </td>
  <td>
<input type="text" name="modelo" id="modelo" size="48" maxlength="28" value="<?php echo $vehiculo->modelo ?>">
  </td>
 </tr>
 <tr height="25">
  <td>TIPO DE VEH&Iacute;CULO </td>
  <td> 
   <select name="tipo_vehiculo" id="tipo_vehiculo" Value="<?php echo $vehiculo->tipo_vehiculo ?>" >
     <option value="turismo" <?php if ($vehiculo->tipo_vehiculo=="TURISMO"){ echo "selected"; }?>>TURISMO 
     <option value="deportivo" <?php if ($vehiculo->tipo_vehiculo=="DEPORTIVO"){ echo "selected"; }?>>DEPORTIVO 
     <option value="4X4" <?php if ($vehiculo->tipo_vehiculo=="4X4"){ echo "selected"; }?>>4X4 
     <option value="furgoneta" <?php if ($vehiculo->tipo_vehiculo=="FURGONETA"){ echo "selected"; }?>>FURGONETA 
     <option value="otro" <?php if ($vehiculo->tipo_vehiculo=="OTRO"){ echo "selected"; }?>>OTRO 
     </select>
  </td>
 </tr>
 <tr height="25">
  <td>MATR&Iacute;CULA </td>
  <td>
<input type="text" name="matricula" id="matricula" size="12" maxlength="12" value="<?php echo $vehiculo->matricula ?>">
  </td>
 </tr>
 <tr height="25">
  <td>A&Ntilde;O DE MATRICULACI&Oacute;N </td>
  <td>
 <input type="text" name="anyo_matricula" id="anyo_matricula" size="4" maxlength="4" value="<?php echo $vehiculo->fecha_mat ?>">
 &nbsp; &nbsp;
     KIL&Oacute;METROS
    <input type="text" name="kilometros" id="kilometros" size="6" maxlength="6" value="<?php echo $vehiculo->kilometros ?>">
  </td>
 </tr>
 <tr height="25">
  <td>FECHA DE PUBLICACI&Oacute;N <b>(AAAA-MM-DD) </b> </td>
  <td>
<input type="text" name="fecha_pub" id="fecha_public" size="10" maxlength="10" value="<?php echo $vehiculo->fecha_pub ?>"> 
     &nbsp; &nbsp;
    P.M.A.
  <input type="text" name="pma" id="pma" size="5" maxlength="5" value="<?php echo $vehiculo->pma ?>">
  </td>
 </tr>
 <tr height="25">
  <td>PRECIO DE VENTA </td>
  <td>
<input type="text" name="precio_venta" id="pvp" size="6" maxlength="6" value="<?php echo $vehiculo->pvp ?>">
  </td>
 </tr>
 <tr height="25">
 <td>PRECIO NUEVO </td>
  <td>
<input type="text" name="precio_nuevo" id="precio_nuevo" size="6" maxlength="6" value="<?php echo $vehiculo->precio_nuevo ?>">
  <td>
 </tr>
 <tr height="25">
 <td>PRECIO DE COMPRA </td>
  <td>
<input type="text" name="precio_compra" id="precio_compra" size="6" maxlength="6" value="<?php echo $vehiculo->precio_compra ?>">
  <td>
 </tr>
 <tr height="25">
  <td><br />EQUIPAMIENTO </td>
  <td>
  
  <textarea name="equipamiento" id="equipamiento" value="<?php echo $vehiculo->equipamiento ?>"rows="2" cols="44"> </textarea>
  </td>
 </tr>
     </table>
 <p>
   <br/>
    <input type="submit" name="boton" id="boton" value="LIMPIAR" tabindex="14" class="boton" style='width:70px'/>
    <input type="submit" name="boton" id="boton" value="GUARDAR" tabindex="14" class="boton"style='width:100px'/>
    <input type="submit" name="boton" id="boton" value="BORRAR" tabindex="15" class="boton" style='width:100px'/>
    <input type="submit" name="boton" id="boton" value="CARGAR" tabindex="16" class="boton" style='width:100px'/>
    <input type="button" name="volver" id="volver" value="VOLVER" onclick="window.location.href='privado.php'" tabindex="17" class="boton" style='width:80px'/>
    <input type="button" value="SUBIR_FOTOGRAFIAS" onclick="window.location.href='subirFotos.php'"class="boton" style='width:170px'/>
</p>  
</form>
El código que lo procesa:
Código PHP:
function Conectarse()
{
 
$db_host="localhost"// Host al que conectar, habitualmente es el &lsquo;localhost&rsquo;
 
$db_nombre="coches"// Nombre de la Base de Datos que se desea utilizar
 
$db_user="root"// Nombre del usuario con permisos para acceder
 
$db_pass=""// Contraseña de dicho usuario
 
// Ahora estamos realizando una conexión y la llamamos &lsquo;$link&rsquo;
 
$link=mysql_connect($db_host$db_user$db_pass) or die ("ERROR CONECTANDO A LA BASE DE DATOS.");
 
// Seleccionamos la base de datos que nos interesa
 
mysql_select_db($db_nombre ,$link) or die("ERROR SELECCIONANDO LA BASE DE DATOS."); 
 
// Devolvemos $link porque nos hará falta más adelante, cuando queramos hacer consultas.
 
return $link;
}

function 
voToHtml(){
    
$tabla="";
$conexion Conectarse();
if (!
$conexion)
  {
  die(
'Could not connect: ' mysql_error());
  }

$resultado mysql_query("SELECT marca, modelo, tipo_vehiculo, matricula, fecha_mat, equipamiento, fecha_pub, 
kilometros, pma, pvp, precio_nuevo, precio_compra FROM vo"
);

while(
$row mysql_fetch_array($resultado))
  {
  
$tabla=$tabla$row['marca'] . " " $row['modelo'] . " " $row['tipo_vehiculo']. " "$row['matricula']
  . 
" "$row['fecha_mat']. " "$row['equipamiento']. " "$row['fecha_pub']. " "$row['kilometros']. 
  
" "$row['pma']. " "$row['pvp']. " "$row['precio_nuevo']. " "$row['precio_compra']. "<br />";
    
  }

mysql_close($conexion);
echo 
$tabla;
}

function 
loadDb(){
    
    
$conexion=Conectarse();
    
    
$resultado=mysql_query("select * from vo",$conexion);
    
    while(
$row mysql_fetch_array($resultado)) { 
    
        echo
"<tr><td>&nbsp;%s</td><td>&nbsp;%s</td><td>&nbsp;%s</td><td>&nbsp;%s</td><td>&nbsp;%s</td><td>&nbsp;%s</td><td>&nbsp;%s</td><td>&nbsp;%s</td><td>&nbsp;%s</td><td>&nbsp;%s</td><td>&nbsp;%s</td><td>&nbsp;%s</td><td>&nbsp;%s</td></tr>"$row["MARCA"],$row["MODELO"],$row["TIPO DE VEHICULO"],$row["MATRICULA"],$row["AÑO DE MATRICULACION"],$row["KILOMETROS"],$row["FECHA DE PUBLICACION"],$row["P.M.A."],$row["PVP"],$row["PRECIO NUEVO"],$row["PRECIO DE COMPRA"],$row["EQUIPAMIENTO"];
    }
    
    
mysql_free_result($resultado);
    
    
mysql_close($conexion);
}

//Archivo de la clase

class VoDAOClass {
          var 
$marca;
          var 
$modelo;
          var 
$tipo_vehiculo;
          var 
$matricula;
          var 
$fecha_mat;
          var 
$equipamiento;
          var 
$fecha_pub;
          var 
$kilometros;
          var 
$pma;
          var 
$pvp;
          var 
$precio_nuevo;
          var 
$precio_compra;          
          
          function 
__construct() {
                       
$marca="";
                       
$modelo="";
                       
$tipo_vehiculo="";
                       
$matricula="";
                       
$fecha_mat="";
                       
$equipamiento="";
                       
$fecha_pub="";
                       
$kilometros="";
                       
$pma="";
                       
$precio_venta="";
                       
$precio_nuevo="";
                       
$precio_compra="";                       
         }
         function 
load($_matricula){
                  
$conexion=Conectarse();
                 
$laSql="select marca, modelo, tipo_vehiculo, matricula, fecha_mat, equipamiento,"
                  
." fecha_pub, kilometros, pma, pvp, precio_nuevo, precio_compra" 
                  
." from vo where matricula='".$_matricula."'";
                 
$resultado=mysql_query($laSql,$conexion);
                  if (
$row mysql_fetch_array($resultado)){
                    
$this->marca $row["marca"];
                    
$this->modelo $row["modelo"];
                    
$this->tipo_vehiculo $row["tipo_vehiculo"];
                    
$this->matricula $row["matricula"];
                    
$this->fecha_mat $row["fecha_mat"];
                    
$this->equipamiento $row["equipamiento"];
                    
$this->fecha_pub $row["fecha_pub"];
                    
$this->kilometros $row["kilometros"];
                    
$this->pma $row["pma"];
                    
$this->pvp $row["pvp"];
                    
$this->precio_nuevo $row["precio_nuevo"];
                    
$this->precio_compra $row["precio_compra"];
                }                
                
mysql_close($conexion); 
         }
         function 
save(){
                if (
$this->matricula!=""){
                    if (
$this->exist()==1){
                        
$conexion=Conectarse();
                         
mysql_query("update vo set marca='".$this->marca."', "
                        
."modelo='".$this->modelo."', "
                        
."tipo_vehiculo='".$this->tipo_vehiculo."' "                        
                        
."fecha_mat='".$this->fecha_mat."', "
                        
."equipamiento='".$this->equipamiento."', "
                        
."fecha_pub='".$this->fecha_pub."', "
                        
."kilometros='".$this->kilometros."', "
                        
."pma='".$this->pma."', "
                        
."pvp='".$this->pvp."', "
                        
."precio_nuevo='".$this->precio_nuevo."', "
                        
."precio_compra='".$this->precio_compra."' "                         
                        
." where matricula='".$this->matricula."'",$conexion);
                        
mysql_close($conexion);                                         
                    }
                    else {
                        
$conexion=Conectarse();
                         
mysql_query("insert into vo (marca,modelo,tipo_vehiculo,matricula,fecha_mat,equipamiento,fecha_pub,kilometros
                        ,pma,pvp,precio_nuevo,precio_compra) values ('"
.$this->marca."', '"
                        
.$this->modelo."', '".$this->tipo_vehiculo."', '".$this->matricula."', '".
                        
$this->fecha_mat."', '".$this->equipamiento."', '".$this->fecha_pub."', '".
                        
$this->kilometros."', '".$this->pma."', '".$this->pvp."', '".
                        
$this->precio_nuevo."', '".$this->precio_compra."', ')",$conexion);
                        
mysql_close($conexion);
                    }                    
                }
         }
         function 
exist(){
             
$resultado=0;
             
$conexion=Conectarse();
                 
$resultado=mysql_query("select * from vo where matricula='".$this->matricula."'",$conexion);
                 if (
$row mysql_fetch_array($resultado)){
                    
$resultado=1;
                 }
                 else 
$resultado=0;
                
mysql_close($conexion);
                return 
$resultado;
         } 
Espero que así lo veas claro. Gracias.
  #4 (permalink)  
Antiguo 02/03/2012, 02:10
Avatar de repara2  
Fecha de Ingreso: septiembre-2010
Ubicación: München
Mensajes: 2.445
Antigüedad: 13 años, 7 meses
Puntos: 331
Respuesta: Cargar campo de BD en textarea

El código que posteas no es el controlador. Veo la classe y las funciones relacionadas pero falta en script que llama a las funciones y crea el objeto.
__________________
Fere libenter homines, id quod volunt, credunt.
  #5 (permalink)  
Antiguo 02/03/2012, 02:15
 
Fecha de Ingreso: enero-2012
Mensajes: 52
Antigüedad: 12 años, 2 meses
Puntos: 1
Exclamación Respuesta: Cargar campo de BD en textarea

Código PHP:
<?php
    session_start
();
    if (isset(
$_SESSION["autentificado"])){
     if (
$_SESSION["autentificado"]=="no"){
        
header("Location: privado.php");
        exit();
     }
    }
    else 
        
header("Location: privado.php");
        
    if (!isset(
$_SESSION["vehiculo"])){
        
$vehiculo=new VoDAOClass();
        
$_SESSION["vehiculo"]= $vehiculo;        
    }
    else 
$vehiculo=$_SESSION["vehiculo"];
?>
  #6 (permalink)  
Antiguo 02/03/2012, 02:34
Avatar de repara2  
Fecha de Ingreso: septiembre-2010
Ubicación: München
Mensajes: 2.445
Antigüedad: 13 años, 7 meses
Puntos: 331
Respuesta: Cargar campo de BD en textarea

Ok, no sé si este es todo el código o falta algo. En total, todo el código que posteas no hace absolutamente nada, te pongo los comentarios en PHP:

Código PHP:
Ver original
  1. $vehiculo=new VoDAOClass();//Llama al constructor de la classe pero el constructor no hace nada
  2.         $_SESSION["vehiculo"]= $vehiculo;

Constructor:

Código PHP:
Ver original
  1. function __construct() {
  2.         $marca="";
  3.         $modelo="";
  4.         $tipo_vehiculo="";
  5.         $matricula="";
  6.         $fecha_mat="";
  7.         $equipamiento="";
  8.         $fecha_pub="";
  9.         $kilometros="";
  10.         $pma="";
  11.         $precio_venta="";
  12.         $precio_nuevo="";
  13.         $precio_compra="";
  14. //Este código no hace nada, primero porque las variables son locales, segundo porque no llama a ninguna otra función
  15.     }

Para que funcione, deberías hacer algo así:

Código PHP:
Ver original
  1. if (isset($_SESSION["autentificado"])){
  2.      if ($_SESSION["autentificado"]=="no"){
  3.         header("Location: privado.php");
  4.         exit();
  5.      }
  6.     }
  7.     else
  8.         header("Location: privado.php");
  9.        
  10.     if (!isset($_SESSION["vehiculo"]) && isset($_POST)){
  11.         $v = new VoDAOClass();
  12.         if(!$vehiculo->load($_POST['matricula']))
  13.         {
  14.             $vehiculo->matricula = "";
  15.             $_SESSION["vehiculo"] = $vehiculo->save();
  16.         };
  17.            
  18.     }
  19.     else $vehiculo=$_SESSION["vehiculo"];

La classe hay que reescribirla porque está mal diseñada y tiene varios fallos pero supongo que te podría funcionar. Al tu código, tienes que agregarle el envio del formulario, si se está enviando el form entonces guardar el objeto, de lo contrario crearlo. Es un poco confuso el código.
__________________
Fere libenter homines, id quod volunt, credunt.
  #7 (permalink)  
Antiguo 02/03/2012, 05:14
 
Fecha de Ingreso: febrero-2012
Ubicación: Bilbao
Mensajes: 33
Antigüedad: 12 años, 2 meses
Puntos: 3
Respuesta: Cargar campo de BD en textarea

Hola

Sin mirar todo el codigo que mandas, detecto que pones value al textarea....

Pregunto: si muestras el valor en otro sitio, lo muestra bien? lo pregunto para saber si esta llegando bien el valor sin mirar el codigo....

Si es asi, prueba a ponerlo asi:
<textarea><?php echo $BASEDEDATOS_VALOR?></textarea>

Saludos
__________________
www.imacreste.com

Etiquetas: bd, formulario, textarea, campos
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 23:12.