View Full Version : Displaying a row depending on user

06-25-2010, 08:02 AM
Hey there

I am trying to create a profile page. Where the user that is signed in will have their info displayed. Here is what I have so far: profile.php

<?php include("tophead.php"); ?>
<?php include("header.php"); ?>
// Adjust MySQL connection settings...
$password = "*****";
$hostname = "localhost";
$database = "******";

// Connect to MySQL...
$conn = mysql_connect($hostname, $username, $password) or die("Connecting to MySQL failed");
mysql_select_db($database, $conn) or die("Selecting MySQL database failed");

// Run our query, see if session username exists in session field...
$sql="select fname,lname,email from users where username='{$_SESSION['username']}' limit 1";

// Parse our results into $data (as an associative array)...

// If one row was found in the result set, username exists...
if ($mysql_num_rows==1) {
print "Welcome, {$data['fname']} {$data['lname']}, your E-Mail address is {$data['email']}";
// Otherwise...
else {
print "Sorry, the username {$_SESSION['username']} was not found in our database...";

But when I go to the page it says:
"Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource on line 19" which is $data=mysql_fetch_assoc($result);

I am at a complete lost. Any help or ways to change it will help. Here is basically what I would like... the page will take the user and display their info in their row in the mysql database. Is it even possible?

06-25-2010, 08:07 AM
It means the query you wrote is wrong. Depending on your DB, it might be case sensitive, so I'd start by making sure cases match up. After that, you need to sanitize your DB entry, otherwise people can really mess with your stuff.

Without seeing how your table is setup, I can't say much else.

06-25-2010, 08:17 AM

If there is any other info you need, let me know! Also, if you know have a script that does this already, could you share?

06-25-2010, 08:28 AM
Heh... the table in your DB is 'user' and the table in your query is 'users' :p

06-25-2010, 08:35 AM
LOL WOW! Such a simple mistake. Ok, so I went to the page and now the page is blank :o
It says the username does not exist like it should in case there is an error, but I was most definitely existed.

06-25-2010, 08:42 AM
Woot got it working! I changed the code a bit though:

Before the line at


Changed it to


Thanks for all your help!