Foros del Web » Programando para Internet » PHP »

PHP OO Insertar datos en input

Estas en el tema de Insertar datos en input en el foro de PHP en Foros del Web. Hola amigos, necesito ayuda con mi proyecto, ya que lo tengo que entregarlo el lunes y mirar a que dia estamos. Mi proyecto se basa ...
  #1 (permalink)  
Antiguo 04/10/2013, 14:08
 
Fecha de Ingreso: noviembre-2012
Mensajes: 8
Antigüedad: 11 años, 5 meses
Puntos: 0
Exclamación Insertar datos en input

Hola amigos, necesito ayuda con mi proyecto, ya que lo tengo que entregarlo el lunes y mirar a que dia estamos.
Mi proyecto se basa en 2 partes. 1 que es joomla y 2 una web php que va integrada en joomla.
Mi problema viene que no soy capad de mostrar los datos registrados en la BD anteriormente en unos INPUT que se muestran cuando haces login. Os dejo todos los codigos:

Este es el registro:
Cita:
<!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=utf-8" />
<title>Documento sin título</title>
</head>

<body>
<div align="center">
<?php
include('acceso_db.php'); // incluimos el archivo de conexión a la Base de Datos
if(isset($_POST['enviar'])) { }
// Procedemos a comprobar que los campos del formulario no estén vacíos
$sin_espacios = count_chars($_POST['usuario_nombre'], 1);
if(empty($_POST['usuario_nombre'])) { // comprobamos que el campo usuario_nombre no esté vacío
echo "No has ingresado tu usuario. <br><br><br><br><br><br> <a href='javascript:history.back();'>Reintentar</a><br><br><br><br><br><br><br><br><br><br><br><br> <br><br><br><br><br><br>";
}else if(empty($_POST['usuario_clave'])) { // comprobamos que el campo usuario_clave no esté vacío
echo "No has ingresado contrase&ntilde;a. <br><br><br><br><br><br> <a href='javascript:history.back();'>Reintentar</a><br><br><br><br><br><br><br><br><br><br><br><br> <br><br><br><br><br><br>";
}else {
// "limpiamos" los campos del formulario de posibles códigos maliciosos
$usuario_nombre = mysql_real_escape_string($_POST['usuario_nombre']);
$usuario_clave = mysql_real_escape_string($_POST['usuario_clave']);
$drop1 = ($_POST['drop1']);
$drop2 = ($_POST['drop2']);
$drop3 = ($_POST['drop3']);
$drive1 = ($_POST['drive1']);
$drive2 = ($_POST['drive2']);
$drive3 = ($_POST['drive3']);
$sky1 = ($_POST['sky1']);
$sky2 = ($_POST['sky2']);
$sky3 = ($_POST['sky3']);
$mega1 = ($_POST['mega1']);
$mega2 = ($_POST['mega2']);
$mega3 = ($_POST['mega3']);
$box1 = ($_POST['box1']);
$box2 = ($_POST['box2']);
$box3 = ($_POST['box3']);
$one1 = ($_POST['one1']);
$one2 = ($_POST['one2']);
$one3 = ($_POST['one3']);
// comprobamos que el usuario ingresado no haya sido registrado antes
$sql = mysql_query("SELECT usuario_nombre FROM usuarios WHERE usuario_nombre='".$usuario_nombre."'");
if(mysql_num_rows($sql) > 0) {
echo "El nombre usuario elegido ya ha sido registrado anteriormente. <br><br><br><br><br><br> <a href='javascript:history.back();'>Reintentar</a><br><br><br><br><br><br><br><br><br><br><br><br> <br><br><br><br><br><br>";
}else {
$usuario_clave = md5($usuario_clave); // encriptamos la contraseña ingresada con md5
}
// ingresamos los datos a la BD
$reg = mysql_query("INSERT INTO nube (usuario_nombre, usuario_clave, drop1, drop2, drop3, drive1, drive2, drive3, sky1, sky2, sky3, mega1, mega2, mega3, box1, box2, box3, one1, one2, one3) VALUES ('".$usuario_nombre."', '".$usuario_clave."', '".$drop1."', '".$drop2."', '".$drop3."', '".$drive1."', '".$drive2."', '".$drive3."', '".$sky1."', '".$sky2."', '".$sky3."', '".$mega1."', '".$mega2."', '".$mega3."', '".$box1."', '".$box2."', '".$box3."', '".$one1."', '".$one2."', '".$one3."')" );
if($reg) {
echo
header ("Location: ./acceso.php");
}else {
echo "ha ocurrido un error y no se registraron los datos. <br><br><br><br><br><br> <br><br><br><br><br><br> <br><br><br><br><br><br> <br><br><br><br><br><br> <br><br><br><br><br><br>";
}
}
?>
</div>
</body>
</html>
Y aquí donde quero que me muestre los datos en los input:
Cita:
<!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=utf-8" />
<title>Documento sin título</title>
</head>

<body>
<p align="center">&nbsp;</p>
<p align="center">
<?php
include ("./acceso sin imagen.php");
if(isset($_SESSION['usuario_nombre']))
?>
</p>
<p align="center">&nbsp;</p>
<p align="center">&nbsp;</p>
<div align="center">
<table width="200" border="5">
<tr>
<td><p><img src="http://www.forosdelweb.com/f18/Nube/images/Nube/descarga (4).jpg" width="225" height="225" alt="Dropbox" /></p>
<p align="center">Usuario:
<input type="text" name="drop1"/>
</p>
<p align="center">Pass:
<input type="text" name="drop2"/>
</p>
<p align="center">Alias:
<input type="text" name="drop3"/>
</p>
<form id="form1" name="form1" method="post" action="drop.php">
<div align="center">
<p>
<input type="button" name="Submit" value=" Entrar " onclick="window.open('https://www.dropbox.com/', 'popup')">
</p>
</div>
</form>
<p align="center">&nbsp;</p></td>
</tr>
</table>
</div>
<p align="center">&nbsp;</p>
<div align="center">
<table width="200" border="5">
<tr>
<td><p><img src="http://www.forosdelweb.com/f18/Nube/images/Nube/descarga (9).jpg" width="225" height="225" alt="Drive" /></p>
<p align="center">Usuario:
<input type="text" name="drive1"/>
</p>
<p align="center">Pass:
<input type="text" name="drive2"/>
</p>
<p align="center">Alias:
<input type="text" name="drive3"/>
</p>
<form id="form2" name="form2" method="post" action="">
<div align="center">
<p>
<input type="button" name="Submit" value=" Entrar " onclick="window.open('https://drive.google.com/‎', 'popup')">
</p>
</div>
</form>
<p align="center">&nbsp;</p>

</td>
</tr>
</table>
</div>
<p align="center">&nbsp;</p>
<div align="center">
<table width="200" border="5">
<tr>
<td><p><img src="http://www.forosdelweb.com/f18/Nube/images/Nube/images (38).jpg" width="225" height="225" alt="SkyDrive" /></p>
<p align="center">Usuario:
<input type="text" name="sky1"/>
</p>
<p align="center">Pass:
<input type="text" name="sky2"/>
</p>
<p align="center">Alias:
<input type="text" name="sky3"/>
</p>
<form id="form3" name="form3" method="post" action="">
<div align="center">
<p>
<input type="button" name="Submit" value=" Entrar " onclick="window.open('https://skydrive.live.com/‎', 'popup')">
</p>
</div>
</form>
<p align="center">&nbsp;</p></td>
</tr>
</table>
</div>
<p align="center">&nbsp;</p>
<div align="center">
<table width="200" border="5">
<tr>
<td><p><img src="http://www.forosdelweb.com/f18/Nube/images/Nube/images (29).jpg" width="225" height="225" alt="Mega" /></p>
<p align="center">Usuario:
<input type="text" name="mega1"/>
</p>
<p align="center">Pass:
<input type="text" name="mega2"/>
</p>
<p align="center">Alias:
<input type="text" name="mega3"/>
</p>
<form id="form4" name="form4" method="post" action="">
<div align="center">
<input type="button" name="Submit" value=" Entrar " onclick="window.open('https://mega.co.nz/', 'popup')">
</div>
</form>
<p align="center">&nbsp;</p></td>
</tr>
</table>
</div>
<p align="center">&nbsp;</p>
<div align="center">
<table width="200" border="5">
<tr>
<td><p><img src="http://www.forosdelweb.com/f18/Nube/images/Nube/descarga (20).jpg" width="225" height="225" alt="box" /></p>
<p align="center">Usuario:
<input type="text" name="box1"/>
</p>
<p align="center">Pass:
<input type="text" name="box2"/>
</p>
<p align="center">Alias:
<input type="text" name="box3"/>
</p>
<form id="form5" name="form5" method="post" action="">
<div align="center">
<input type="button" name="Submit" value=" Entrar " onclick="window.open('https://www.box.com/', 'popup')">
</div>
</form>
<p align="center">&nbsp; </p></td>
</tr>
</table>
</div>
<p align="center">&nbsp;</p>
<div align="center">
<table width="200" border="5">
<tr>
<td><p><img src="http://www.forosdelweb.com/f18/Nube/images/Nube/images (42).jpg" width="215" height="211" alt="Ubuntu One" /></p>
<p align="center">Usuario:
<input type="text" name="one1"/>
</p>
<p align="center">Pass:
<input type="text" name="one2"/>
</p>
<p align="center">Alias:
<input type="text" name="one3"/>
</p>
<form id="form6" name="form6" method="post" action="">
<div align="center">
<input type="button" name="Submit" value=" Entrar " onclick="window.open('https://one.ubuntu.com/', 'popup')">
</div>
</form>
<p align="center">&nbsp; </p></td>
</tr>
</table>
</div>
<p align="center">&nbsp;</p>
</body>
</html>
Gracias de antemano.

Hay mas codigo pero lo veo innecesario ponerlo aqui, lo puedo enviar por privado.

Última edición por bladeoff; 04/10/2013 a las 14:14
  #2 (permalink)  
Antiguo 09/10/2013, 10:50
Avatar de iukaeru  
Fecha de Ingreso: mayo-2012
Mensajes: 127
Antigüedad: 11 años, 11 meses
Puntos: 12
Respuesta: Insertar datos en input

A ver a ver a ver... entiendo que:

//Recoges unos datos que vienen de un formulario
$drop1 = ($_POST['drop1']); ................

//Consultas en la BD (Te sugiero abandodes mysql y cambies a mysqli)
$sql = mysqli_query($link, "SELECT usuario_nombre FROM usuarios WHERE .............

//Y en base al resultado, meter de nuevo los valores en HTML
NO USAR: if(mysql_num_rows($sql) > 0) { .........................
USAR: $row = mysqli_fetch_array($sql){ .........................
//Y por cada columna $row asociada a un campo, la incluyes en tu código HTML
$nombre = $row["nombre"];

//Y devolver la variable a tu código HTML
//HTML
........................
<input type="text" value="<?php print $nombre; ?>" />
........................
//FIN HTML

¿Era lo que querías?

Etiquetas: formulario, html, input, mysql, registro, select, sql, usuarios
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 05:17.