CJLeah Posted April 18, 2006 Share Posted April 18, 2006 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']); ?> Quote Link to comment Share on other sites More sharing options...
Caesar Posted April 18, 2006 Share Posted April 18, 2006 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. Quote Link to comment Share on other sites More sharing options...
Barand Posted April 18, 2006 Share Posted April 18, 2006 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. Quote Link to comment Share on other sites More sharing options...
CJLeah Posted April 18, 2006 Author Share Posted April 18, 2006 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 Link to comment Share on other sites More sharing options...
Caesar Posted April 18, 2006 Share Posted April 18, 2006 [!--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. Quote Link to comment Share on other sites More sharing options...
CJLeah Posted April 18, 2006 Author Share Posted April 18, 2006 [!--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] Quote Link to comment Share on other sites More sharing options...
Caesar Posted April 18, 2006 Share Posted April 18, 2006 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.