Foros del Web » Programando para Internet » PHP »

llenar campos de texto

Estas en el tema de llenar campos de texto en el foro de PHP en Foros del Web. Hola, quiero hacer un formulario de actualización de una tabla de Mysql y lo que pretendo es hacer un formulario que se llenen con los ...
  #1 (permalink)  
Antiguo 27/12/2017, 09:05
 
Fecha de Ingreso: noviembre-2003
Mensajes: 499
Antigüedad: 20 años, 4 meses
Puntos: 7
llenar campos de texto

Hola, quiero hacer un formulario de actualización de una tabla de Mysql y lo que pretendo es hacer un formulario que se llenen con los datos de una tabla, no tengo idea ni como empezar, alguien me da una mano ???

Gracias
  #2 (permalink)  
Antiguo 27/12/2017, 11:08
Avatar de xfxstudios  
Fecha de Ingreso: junio-2015
Ubicación: Valencia - Venezuela
Mensajes: 2.448
Antigüedad: 8 años, 9 meses
Puntos: 263
Respuesta: llenar campos de texto

Consultas tu base:
Código PHP:
Ver original
  1. $da = $db->query("SELECT * FROM tabla WHERE id = '$id");
  2. $row = $da->fetch_object();

Muestra valor en campo:
Código HTML:
Ver original
  1. <input type="text" name="loquesea" value="<?php echo $row->campo; ?>"/>

igualk todo va a depender de que estes haciendo, en que contexto se tgenera la consulta, como estes pasando los valores de filtrado para la consulta entre otros. Da mas detalles.
__________________
[email protected]
HITCEL
  #3 (permalink)  
Antiguo 29/12/2017, 06:19
 
Fecha de Ingreso: noviembre-2003
Mensajes: 499
Antigüedad: 20 años, 4 meses
Puntos: 7
Respuesta: llenar campos de texto

Hola amigos hice este grupo de programas y ne da el error de que no encuentra el registro y no entiendo por que, en este formulario ingreso el registro a buscar

Código PHP:
<!doctype html>
<
html>
<
head>
  <
title>Modificación</title>
</
head>
<
body>
  <
form method="post"  action="pagina2.php">
    
Ingrese el código de artículo a modificar:
    <
input type="text" name="nresol" size="10" required>
    <
br>
    <
input type="submit" value="Consultar">
  </
form>
</
body>
</
html
Este me muestra el registro donde veo las datos a modificar
Código PHP:
<head>
  <title>Modificación</title>
</head>  
<body>
  
  <?php
    $mysql
=new mysqli("localhost","root","","tural");
    if (
$mysql->connect_error)
      die(
"Problemas con la conexión a la base de datos");
  
    
$registro=$mysql->query("select * from prestad where N_Resol = $_REQUEST[nresol]") or
      die(
$mysql->error);
     
    if (
$reg=$registro->fetch_array())
    {
  
?>
    <form method="post" action="pagina3.php">
      Nombre y Apellido:
      <input type="text" name="Nyap" size="50" value="<?php echo $reg['Nyap']; ?>"/>
      <br>
      Codigo de Actividad:
      <input type="text" name="Cod_act" size="50" value="<?php echo $reg['Cod_act']; ?>"/>
      <br>
      Codigo de Area:
      <input type="text" name="Cod_area" size="50" value="<?php echo $reg['Cod_area']; ?>"/>
      <br>
      Nombre de Fant:
      <input type="text" name="Nombre_fant" size="50" value="<?php echo $reg['Nombre_fant']; ?>"/>
      <br>
      Telefono:
      <input type="text" name="Telefono" size="10" value="<?php echo $reg['Telefono']; ?>"/>      
      <br>    
      Mail:
      <input type="text" name="Mail" size="50" value="<?php echo $reg['Mail']; ?>"/>
      <br>      
      <input type="hidden" name="nresol" value="<?php echo $reg['N_Resol']; ?>"/>     
      <br> 
      <input type="submit" value="Confirmar">
    </form>
  <?php
    
}      
    else
      echo 
'No existe este prestador';
    
    
$mysql->close();

  
?>  
</body>
este hace la modificacion

Código PHP:
<!doctype html>
<html>
<head>
  <title>Modificación</title>
</head>  
<body>
  
  <?php
    $mysql
=new mysqli("localhost","root","","tural");
    if (
$mysql->connect_error)
      die(
"Problemas con la conexión a la base de datos");
  
    
$mysql->query("update prestad set 
                           Nyap='$_REQUEST[Nyap]',
                          Cod_act =$_REQUEST[Cod_act],
                           Cod_area=$_REQUEST[Cod_area],
                           Nombre_fant=$_REQUEST[Nombre_fant],
                           Telefono=$_REQUEST[Telefono],
                           Mail=$_REQUESTMail]
              where N_Resol=$_REQUEST[N_Resol]"
) or
      die(
$mysql->error);
     
    echo 
'Se modificaron los datos del artículo';
    
    
$mysql->close();

  
?>  
</body>
</html>
  #4 (permalink)  
Antiguo 29/12/2017, 06:51
Avatar de xfxstudios  
Fecha de Ingreso: junio-2015
Ubicación: Valencia - Venezuela
Mensajes: 2.448
Antigüedad: 8 años, 9 meses
Puntos: 263
Respuesta: llenar campos de texto

Prueba así

Código PHP:
Ver original
  1. $db = new MySQLi('host', 'usuario', 'clave', 'base');
  2.         if($db->connect_error) {
  3.             die('Error de conexion ('.$db->connect_errno.')'
  4.                 .$db->connect_errno);
  5.         };
  6. $valor = $_POST['nresol'];
  7. $registro=$db->query("select * from prestad where N_Resol = '$valor'");
  8. $cant = mysqli_num_rows($registro);
  9.  
  10. if($cant>=1){
  11.     $reg = $registro->fetch_array()) {
  12. //RESTO DE TU CODIGO
__________________
[email protected]
HITCEL
  #5 (permalink)  
Antiguo 29/12/2017, 07:37
 
Fecha de Ingreso: noviembre-2003
Mensajes: 499
Antigüedad: 20 años, 4 meses
Puntos: 7
Respuesta: llenar campos de texto

Amigo:
Gracias por tu respuesta, ahora me da este error en el primer cierre <?, y no entiendo por que

Parse error: syntax error, unexpected ';' in C:\wamp64\www\alterna\actual\pagina2.php on line 16
Código PHP:
<head>
  <title>Modificación</title>
</head>  
<body>
  <?php
    $db 
= new MySQLi('localhost''root''''tural');
        if(
$db->connect_error) {
            die(
'Error de conexion ('.$db->connect_errno.')'
                
.$db->connect_errno);
        };
$valor $_POST['nresol'];
$registro=$db->query("select * from prestad where N_Resol = '$valor'");
$cant mysqli_num_rows($registro);
 
if(
$cant>=1) {
    
$reg $registro->fetch_array() {;
  
?>
    <form method="post" action="pagina3.php">
      Nombre y Apellido:
      <input type="text" name="Nyap" size="50" value="<?php echo $reg['Nyap']; ?>"/>
      <br>
      Codigo de Actividad:
      <input type="text" name="Cod_act" size="50" value="<?php echo $reg['Cod_act']; ?>"/>
      <br>
      Codigo de Area:
      <input type="text" name="Cod_area" size="50" value="<?php echo $reg['Cod_area']; ?>"/>
      <br>
      Nombre de Fant:
      <input type="text" name="Nombre_fant" size="50" value="<?php echo $reg['Nombre_fant']; ?>"/>
      <br>
      Telefono:
      <input type="text" name="Telefono" size="10" value="<?php echo $reg['Telefono']; ?>"/>      
      <br>    
      Mail:
      <input type="text" name="Mail" size="50" value="<?php echo $reg['Mail']; ?>"/>
      <br>      
      <input type="hidden" name="nresol" value="<?php echo $reg['N_Resol']; ?>"/>     
      <br> 
      <input type="submit" value="Confirmar">
    </form>
  <?php
    
}      
    else
      echo 
'No existe este prestador';
    
    
$mysql->close();

  
?>  
</body>
</html>
  #6 (permalink)  
Antiguo 29/12/2017, 08:38
Avatar de xfxstudios  
Fecha de Ingreso: junio-2015
Ubicación: Valencia - Venezuela
Mensajes: 2.448
Antigüedad: 8 años, 9 meses
Puntos: 263
Respuesta: llenar campos de texto

en esta linea tiene un ; al final
Código PHP:
Ver original
  1. $reg = $registro->fetch_array() {;

eliminalo
__________________
[email protected]
HITCEL
  #7 (permalink)  
Antiguo 29/12/2017, 08:45
 
Fecha de Ingreso: noviembre-2003
Mensajes: 499
Antigüedad: 20 años, 4 meses
Puntos: 7
Respuesta: llenar campos de texto

Perdon amigo te malde mal el error

Parse error: syntax error, unexpected '?> ' in C:\wamp64\www\alterna\actual\pagina2.php on line 17


Código PHP:
<head>
  <title>Modificación</title>
</head>  
<body>
  <?php
    $db 
= new MySQLi('localhost''root''''tural');
        if(
$db->connect_error) {
            die(
'Error de conexion ('.$db->connect_errno.')'
                
.$db->connect_errno);
        };
$valor $_POST['nresol'];
$registro=$db->query("select * from prestad where N_Resol = '$valor'");
$cant mysqli_num_rows($registro);
 
if(
$cant>=1) {
    
$reg $registro->fetch_array() {
  
?>
    <form method="post" action="pagina3.php">
      Nombre y Apellido:
      <input type="text" name="Nyap" size="50" value="<?php echo $reg['Nyap']; ?>"/>
      <br>
      Codigo de Actividad:
      <input type="text" name="Cod_act" size="50" value="<?php echo $reg['Cod_act']; ?>"/>
      <br>
      Codigo de Area:
      <input type="text" name="Cod_area" size="50" value="<?php echo $reg['Cod_area']; ?>"/>
      <br>
      Nombre de Fant:
      <input type="text" name="Nombre_fant" size="50" value="<?php echo $reg['Nombre_fant']; ?>"/>
      <br>
      Telefono:
      <input type="text" name="Telefono" size="10" value="<?php echo $reg['Telefono']; ?>"/>      
      <br>    
      Mail:
      <input type="text" name="Mail" size="50" value="<?php echo $reg['Mail']; ?>"/>
      <br>      
      <input type="hidden" name="nresol" value="<?php echo $reg['N_Resol']; ?>"/>     
      <br> 
      <input type="submit" value="Confirmar">
    </form>
  <?php
    
}      
    else
      echo 
'No existe este prestador';
    
    
$mysql->close();

  
?>  
</body>
  #8 (permalink)  
Antiguo 29/12/2017, 10:25
Avatar de xfxstudios  
Fecha de Ingreso: junio-2015
Ubicación: Valencia - Venezuela
Mensajes: 2.448
Antigüedad: 8 años, 9 meses
Puntos: 263
Respuesta: llenar campos de texto

Código PHP:
Ver original
  1. }//FALTA ESTA
  2.  
  3. }else
  4.       echo 'No existe este prestador';
  5.      
  6.     $mysql->close();

aunque al final creo que no hacen falta esas llaves, ni la de inicio ni la de fin, prueba a ver
__________________
[email protected]
HITCEL
  #9 (permalink)  
Antiguo 02/01/2018, 09:15
 
Fecha de Ingreso: noviembre-2003
Mensajes: 499
Antigüedad: 20 años, 4 meses
Puntos: 7
Respuesta: llenar campos de texto

Hora por que me sale esto, me esta volviendo loooooocccooooooooooooo

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '9 354 112-5908 ', Mail ='[email protected] '' at line 5

Código PHP:
<!doctype html>
<html>
<head>
  <title>Modificación</title>
</head>  
<body>
  
  <?php
  $valor 
$_POST['nresol'];
  
$Nyap $_POST['Nyap'];
  
$Cod_act $_POST['Cod_act'];
  
$Cod_area $_POST['Cod_area'];
  
$Nombre_fant $_POST['Nombre_fant'];
  
$Tel $_POST['Tel'];
  
$Mail $_POST['Mail'];
  
//$valor = $_POST['nresol'];
  
echo $valor;
    
$mysql=new mysqli("localhost","root","","tural");
    if (
$mysql->connect_error)
     die(
"Problemas con la conexión a la base de datos");
  
    
$mysql->query("update prestad set 
                           Nyap = '$Nyap',
                           Cod_act = '$Cod_act',
                           Cod_area = '$Cod_area',
                           Nombre_fant = $Nombre_fant',
                           Tel = '$Tel',
                           Mail ='$Mail'
              where 'N_Resol'= '$valor'; "
)  
    or die(
$mysql->error);
     
    echo 
'Se modificaron los datos del artículo';
    
    
$mysql->close();

  
?>  
</body>
</html>
  #10 (permalink)  
Antiguo 02/01/2018, 10:55
Avatar de xfxstudios  
Fecha de Ingreso: junio-2015
Ubicación: Valencia - Venezuela
Mensajes: 2.448
Antigüedad: 8 años, 9 meses
Puntos: 263
Respuesta: llenar campos de texto

tienes encerrado el nombre del campo entre comillas

Código PHP:
Ver original
  1. where 'N_Resol'= '$valor'; ")
__________________
[email protected]
HITCEL
  #11 (permalink)  
Antiguo 03/01/2018, 07:01
 
Fecha de Ingreso: noviembre-2003
Mensajes: 499
Antigüedad: 20 años, 4 meses
Puntos: 7
Respuesta: llenar campos de texto

Gracias amigo, muy valios tu ayuda

Etiquetas: campos, formulario, mysql, tabla
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 00:07.