Hey guys,

I am really close with this but can't quite get it right... All I am trying to do is retrieve the users details based on their 'u_id' and display them.

<?php
require ('dbconnect.php');
	$user = $_SESSION['username'];         //Get the users username
	$requestuid = mysql_query("SELECT u_id FROM user_usr WHERE u_username = '$user'");      //Get the users u_id based on their username
	$resultuid = mysql_fetch_assoc($requestuid);
	echo $resultuid['u_id'];          //THIS PRINTS THE USERS ID NO
?>

<table>
	<tr>
		<td>Gender:</td>
		<td>
			<?php 
                                   $request = mysql_query("SELECT u_gender FROM users WHERE u_id = '$resultuid'");  
				$result = mysql_fetch_assoc($request); 
				echo $result['u_gender'];    //THIS DOESN'T PRINT THE USERS GENDER
			?>
		</td>
	</tr>
</table>

In my head this should work, but I can't quite get it. Can anyone see where I'm going wrong?

Many Thanks,
Nonshatter

Recommended Answers

All 2 Replies

Line 6 look correct. but in line 14 you use $resultuid.

To get this working insert a line before line 6 and change the current line 6 and 14 like so:

$ruid = $resultid['u_id'];
echo $ruid;

// line 14:
$request = mysql_query("SELECT u_gender FROM users WHERE u_id = '$ruid'");

Perfect. Thanks for your help!
:icon_cool:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.