Jump to content

SHow current user


CJLeah

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']); ?>
Link to comment
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.
Link to comment
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.
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.