Jump to content

Archived

This topic is now archived and is closed to further replies.

CJLeah

SHow current user

Recommended Posts

I'm having trouble wit a code, i'm quite sure is wrong, what I want is a code that will show the current user, eg Hello Chris. ANyway whats wrong with mine, or whats right, lol. please help :)

<?php mysql_query("SELECT username FROM users"); echo ($_POST['username']); ?>

Share this post


Link to post
Share on other sites
First, this depends on how you determine when a user is online/offline. Do you have a cron job which deletes open sessions if they exceed a certain amount of time of inactivity? Otherwise, anytime someone logs in, and closes their browser without logging out, the session will stay open (If indeed you are using a sessions table in the database) thus, showing these people as "Online".

In regards to your example, nothing in your query gives specifics as to what user you are trying to retrieve from the database.

[code]<?php

$username = $_POST['username'];

$somequery = mysql_query("SELECT * FROM users WHERE username = '$username'");

$result = mysql_fetch_array($somequery);

echo"Hiya $result[username], how the f*ck are you, you ugly bastage?";

?>[/code]

As far as a "who is online" script...that is trickier without knowing what I discussed above....but yeah....

Asuming that the username column is the second one in the table...

[code]<?php

$somequery = mysql_query("SELECT * FROM users WHERE online = '1'");

while ($row = mysql_fetch_array($somequery))

{echo" $row[1] ";}

?>[/code]

I also take it you are running your login script through several checks before you determine whether someone is logged in or not...and other security concerns?

Anyway, good luck bro.

Share this post


Link to post
Share on other sites
Ok, you've shown us code that doesn't work, so now we know what you [b]don't[/b] want.

Perhaps if you told us exactly what you are trying to do we can help you more.

Share this post


Link to post
Share on other sites
sorry, i'm veyr new to php, but basically what i'm trying to do is, show the that users username, when he look at that page, like 'Hello USERNAME how are you?' somthing like that...

that help any better?

Share this post


Link to post
Share on other sites
[!--quoteo(post=366164:date=Apr 18 2006, 03:16 PM:name=Chris Leah)--][div class=\'quotetop\']QUOTE(Chris Leah @ Apr 18 2006, 03:16 PM) [snapback]366164[/snapback][/div][div class=\'quotemain\'][!--quotec--]
sorry, i'm veyr new to php, but basically what i'm trying to do is, show the that users username, when he look at that page, like 'Hello USERNAME how are you?' somthing like that...

that help any better?
[/quote]

Look at my above example.

And consider looking through -> [a href=\"http://www.php.net\" target=\"_blank\"]http://www.php.net[/a] ....Great source.

Share this post


Link to post
Share on other sites
[!--quoteo(post=366172:date=Apr 18 2006, 03:24 PM:name=Caesar)--][div class=\'quotetop\']QUOTE(Caesar @ Apr 18 2006, 03:24 PM) [snapback]366172[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Look at my above example.

And consider looking through -> [a href=\"http://www.php.net\" target=\"_blank\"]http://www.php.net[/a] ....Great source.
[/quote]


I have mate, but not working ..:( but i've jsut tried this also


[code]<?php
$result = mysql_query("SELECT COUNT(*) FROM users WHERE username = '" . $_POST['username'] . "'") or exit(mysql_error());
if (mysql_result($result, 0)) {echo $_POST['username'] . ' how are you?';}
else {echo $_POST['username'] . ' is not in the database';}
?>[/code]

Share this post


Link to post
Share on other sites
Well..no examples will be relevent if your databae tables are named diferently, or if your code is not working properly....the example I provided...works.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.