...

View Full Version : Displaying a row depending on user



blackrain87
06-25-2010, 07: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"); ?>
<?php
// Adjust MySQL connection settings...
$username="******";
$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";
$result=mysql_query($sql,$conn);

// Parse our results into $data (as an associative array)...
$data=mysql_fetch_assoc($result);

// 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...";
}
?>
</body>
</html>


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?

Keleth
06-25-2010, 07: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.

blackrain87
06-25-2010, 07:17 AM
http://files.newestfunny.com/uploads/1277512437.jpg

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?

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

blackrain87
06-25-2010, 07: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.

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

Before the line at


$mysql_num_rows

Changed it to


mysql_num_rows($result)


Thanks for all your help!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum