Sacar la ID de un usuario
(1/1)
xpartano.x:
Hola a todos!
soy nuevo en elhacker.net, y me gustaría que me ayudarais en un pequeño quebradero de cabeza que me está dando.
Estoy creando una página web, que se tira más a aires de una red social.
La página web está hecha por php y mysql
Lo que yo quiero hacer es lo siguiente:
Al acceder a la url de la web me sale un loggin, ahi bn, t pide el user y pass, y al acceder te sale un mensaje de bienvenida y en el menú tengo un apartado que se llama, Mi perfil, que se tratará mas bien de cambiar datos de un form.
Mi idea seria que en el menú accediera a este estilo de ejemplo:
perfil.php?id=123
Quiero que una vez iniciado sesion de cualquier usuario, que lo identifique y saque su ID.
Yo tenía pensado hacer algo similar a esto:
Código:
<?php
include("sql/conex.php");
$link=Conectarse();
$username = $_SESSION["s_username"];
$result=mysql_query("select * from usuarios WHERE username=".$username."",$link);
?>
<?php
while($row = mysql_fetch_array($result,$link)) {
printf("%s",$row["ID"]);
}
mysql_free_result($result);
mysql_close($link);
?>
El problema es que me salta este error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\corleone\id.php on line 9
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in C:\AppServ\www\corleone\id.php on line 12
Necesito ayuda :S:S:S
dark_sargon:
El reporte te dice que el problema es un argumento pasado a mysql_fetch_array.
Intenta así:
Código
while($row = mysql_fetch_array($result)) {
echo "<b>ID del usuario:</b> ".$row[numero];
}
Reemplaza numero por el numero de campo que sea el ID del usuario en tu tabla (empezando a numerar desde el cero).
xpartano.x:
me tira el mismo error con las mismas lineas
Lo que no dije es que mi web lo tengo a través de includes, a ver si puede ser problema de ahi.
Lo que tengo es esto:
menu.php
Código:
<? include ("seguridad.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ítulo</title>
<SCRIPT LANGUAGE="javascript">
<!-- Begin
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=250,height=520');");
}
// End -->
</script>
</head>
<body>
<lu list-style:none;><li><a href="inicio.php">INICIO</a></li>
<hr color="#5a8cb8">
<li>[color=red]<a href="perfil.php?id=<? include ("id.php"); ?>">PERFIL</a>[/color]<br />
<hr color="#5a8cb8" />
</li>
<li><a href="fotos.php">FOTOS</a></li>
<hr color="#5a8cb8"><li><a href="videos.php">VIDEOS</a></li>
<hr color="#5a8cb8"><li><a href="montajes.php">MONTAJES</a></li>
<hr color="#5a8cb8"><li><a href="javascript:popUp('Paquirrin_in_Session_2011/index.php')">MÚSICA</a></li>
<hr color="#5a8cb8">
<li><a href="componentes.php">CORLEONE</a></li>
<hr color="#5a8cb8">
</lu>
</body>
</html>
y dentro del menu está la pagina principal
inicio.php
Código:
<? include ("seguridad.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>
<LINK REL="StyleSheet" HREF="css/web.css" TYPE="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin título</title>
<style type="text/css">
<!--
body {
background-color: #5a8cb8;
}
.Estilo2 {font-size: x-small}
.Estilo4 {
color: #33CCFF;
font-weight: bold;
font-size: x-large;
}
-->
</style></head>
<body>
<div align="center">
<table width="800" height="600" border="0">
<tr>
<td height="100" colspan="2" valign="bottom" bordercolor="#3C658A" background="logo.jpg" bgcolor="#3C658A"><p align="right" class="Estilo2"><span class="Estilo3"><br />USUARIO: <? $username = $_SESSION["s_username"]; echo $username;?> <br /> <a href="salir.php"> </span><img src="cerrar_sesion.gif" border="0"/></a> </td>
</tr>
<tr>
<td width="125" height="600" bordercolor="#3C658A" bgcolor="#3C658A" align="center" valign="top">
<? include('menu.php');?> </td>
<td width="663" bordercolor="#3C658A" bgcolor="#FFFFFF" valign="top"><blockquote>
<p align="left"><font size="+3" color="#0099FF">Hola
<? $username = $_SESSION["s_username"]; echo $username;?>
! </font> </p>
<div align="right"><a href="hacernoticia.php">Publicar noticia</a> </div>
<table width="600" border="0">
<tr>
<td><? include('noticias.php'); ?>
</td>
</tr>
</table>
<p align="center" class="Estilo4"></p>
</blockquote> </td>
</tr>
<tr>
<td colspan="2" bgcolor="#CCCCCC"><? include('derechosdeautor.php');?></td>
</tr>
</table>
</div>
</body>
</html>
No lehe llamado index porque tengo un loggin llamado index.php
Lo que yo quiero es que cuando se loggea, accede a la bd y localiza si esta registrado..ok lo que qiero es que cuando inicie sesion es el sistema mire que si el usuario es "fulanito" le corresponde una ID, esa ID quiero sacarla
Navegación