Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

PHP Assistance

Custom Title Activated
Loyal Member
Joined
Jun 27, 2009
Messages
1,571
Reaction score
170
Hello!

I need help with my PHP Code

I was figuring out why I can't visit other people home page! and I figured yeah me and stupid me... whatever learning

I'm using $_SESSION which means it will always redirects to my information because it's using my session.

PHP:
<?php 
                                $getUserInfo = mysql_query("SELECT * FROM `users` WHERE id = '".$_SESSION[user][id]."'");
                                while ($userInfo= mysql_fetch_assoc($getUserInfo))
                                     {
                                echo ' 
<tbody>
<tr>
<td valign="middle" width="25">
<img style="margin-top: -10px;" src="http://www.habbo.com/habbo-imaging/avatarimage?figure=' .$userInfo['look'] . '&size=m&gesture=sml">
</td>
<td valign="top">
<p style="font-size: 90%;">Username: <strong>' .$userInfo['username'] . '</strong>
<br>Motto: <strong>' .$userInfo['motto'] . '</strong>
<br><i>Last Online: {lastSignedIn}</i></p>
<br/></td>
<td valign="top" style="float: right;">
' . (($userInfo['online'] == "1") ? '
<img src="../app/tpl/skins/Habbo/web-gallery/v2/images/habbo_online.gif"/>':'<img src="../app/tpl/skins/Habbo/web-gallery/v2/images/habbo_offline.gif"/>') . '
</td>
</tr>
</tbody>
</table>
<tbody>
<tr>
';
                               
                               }
                                ?>
 
Newbie Spellweaver
Joined
Aug 9, 2016
Messages
83
Reaction score
11
do something like:
userId = mysql_real_espace_string($_GET['id']);
$getUserInfo = mysql_query("SELECT * FROM `users` WHERE id = '".userId ."'");
...... and so on


Then you should use url like where xx is user id.
 
Upvote 0
Custom Title Activated
Loyal Member
Joined
Jun 27, 2009
Messages
1,571
Reaction score
170
do something like:
userId = mysql_real_espace_string($_GET['id']);
$getUserInfo = mysql_query("SELECT * FROM `users` WHERE id = '".userId ."'");
...... and so on


Then you should use url like where xx is user id.

it breaks the site
 
Upvote 0
Custom Title Activated
Loyal Member
Joined
Jun 27, 2009
Messages
1,571
Reaction score
170
replace 'userId' with '$userId' for both of them, if you didn't already.

And what do you mean with 'It breaks the site'?

Now this happens

Glee - PHP Assistance - RaGEZONE Forums
 
Upvote 0
Newbie Spellweaver
Joined
Aug 9, 2016
Messages
83
Reaction score
11
Well if you're using links like habcheer.co/home/username then your query would need to use usernames too. Lets assume that your non rewrited urls would look like habcheer.co/home?username=test, which it possibly does, you can look into your .htaccess file to make sure.

So the problem with my code was that it was assuming that you would provide it with user id, but instead you were providing it with username.

test this:
$username = mysql_real_espace_string($_GET['username']);
$getUserInfo = mysql_query("SELECT * FROM `users` WHERE username = '".$username."'");
...... and so on

If that doesn't work then please provide your .htaccess file or this will be just guessing for me.

But if you're using usernames on your links then it should just be:
$username = mysql_real_espace_string($_GET['NAME OF YOUR GET VARIABLE HERE']);
$getUserInfo = mysql_query("SELECT * FROM `users` WHERE username = '".$username."'");
...... and so on

And NAME OF YOUR GET VARIABLE will most likely just be "id" or "username", but if isn't, can be found in your .htaccess file.



User Test does exist. and can you by chance provide me example of if-else statement
Well it seems that you still have much to learn. but here i made you an example which should work, i currently don't have anything to test it on, but pretty sure it should work if didn't get any typos in it.

PHP:
if(!empty($_GET['username'])) {
    //if username is set then go on
$username = mysql_real_espace_string($_GET['username']);
$getUserInfo = mysql_query("SELECT * FROM `users` WHERE username = '".$username."'");
} else {
    //else show own profile page
$getUserInfo = mysql_query("SELECT * FROM `users` WHERE id = '".$_SESSION['user']['id']."'");
}

if(mysql_num_rows($getUserInfo) == 0){
    //if query returns nothing then redirect to 404 user not found or where ever you want to e.g.
header("Location: /404");
}
//and so on
 
Last edited:
Upvote 0
Back
Top