Jump to content


Photo

showing other members profile


  • Please log in to reply
29 replies to this topic

#21 almightyegg

almightyegg
  • Members
  • PipPipPip
  • Advanced Member
  • 791 posts
  • LocationEngland

Posted 24 October 2006 - 10:04 PM

right, it no longer displays a delay, but displays my info...
$view = "SELECT * FROM users WHERE users.id='$GET'";
$view2 = mysql_query($view);
$view3 = mysql_fetch_assoc($view2);
$user = $view3[username];

Visit my Game - Under Construction

#22 kirk112

kirk112
  • Members
  • PipPipPip
  • Advanced Member
  • 98 posts
  • LocationEngland

Posted 24 October 2006 - 10:10 PM

it that correct or are you still having problems

#23 almightyegg

almightyegg
  • Members
  • PipPipPip
  • Advanced Member
  • 791 posts
  • LocationEngland

Posted 25 October 2006 - 10:48 AM

still having problems,
the page is: http://www.lordofthe...r/view.php?id=3 so therefore should show the row with id=3 but instead it shows mine (id=1)
Visit my Game - Under Construction

#24 almightyegg

almightyegg
  • Members
  • PipPipPip
  • Advanced Member
  • 791 posts
  • LocationEngland

Posted 25 October 2006 - 11:03 AM

i think i may know why it isnt working but i dont know how to sort it...
$GET = $mem[id];
//$mem[id] is the thing i use to pull up my id

$view = "SELECT * FROM users WHERE users.id='$GET'";
//so here, it is selecting my row??
$view2 = mysql_query($view);
$view3 = mysql_fetch_assoc($view2);
$user = $view3[username];

Visit my Game - Under Construction

#25 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 25 October 2006 - 11:11 AM

OK, it seems that this has been going on a while, and you've also been fed a lot of trap!

Firstly, delete that php.ini file that you created and dropped into that directory.  A few have mentioned register_globals but none have actually explained what it means/does.  So here goes in it's simplest form:

Having register_globals switched on, means that you can refer to a variable in php using the name that was provided in the request object, without the need to specify where it came from.

Example: If I have a form that has one field called 'name' and I use the method 'post' to send it to a php page and I want to use that variable.  If register_globals is switched off (by default in newer versions of php), I have to use this...

echo $_POST['name'];

If register_globals is on then I can use this:

echo $name;

It automatically imports 'name' into the variable name space, meaning I don't need to specify $_POST.

So for your example, you need to use the following code.
<?php
$view = "SELECT * FROM users WHERE id = '{$_GET['id']}' LIMIT 1";
$view2 = mysql_query($view);
$view3 = mysql_fetch_assoc($view2);
$user = $view3['username'];
?>

The above example assumes that the column in the table (users) that contains the unique user ID is called 'id'

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#26 almightyegg

almightyegg
  • Members
  • PipPipPip
  • Advanced Member
  • 791 posts
  • LocationEngland

Posted 25 October 2006 - 11:20 AM

and am i still using
$GET = $mem[id];
??
Visit my Game - Under Construction

#27 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 25 October 2006 - 11:38 AM

Don't call your variable $GET as it's too much like $_GET which is a predefined variable in php.

I'll post a simple bit of code for you to just see if it works, then complicate it and fit the other bits around it.  I've taken this nearly all from your code so it looks familiar to you.

<?php
// Connect to the database
include 'database.php';

// Query the database and assign the results to a variable
$view = "SELECT * FROM users WHERE id = '{$_GET['id']}' LIMIT 1";
$view2 = mysql_query($view) or die("Couldn't execute $sql:\n\n" . mysql_error());
$view3 = mysql_fetch_assoc($view2) or die("Couldn't fetch the results:" . mysql_error());
$user = $view3['username'];

$admin_ids = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

foreach ($admin_ids as $id){
   if ($view3['id'] == $id){
      $admin = "y";
   }
}

if ($admin == "y"){
   echo "{$view3['username']} is an administrator\n";
}
else {
   echo "{$view3['username']} is not an administrator\n";
}
?>

Call this code something like testforadmin.php and make sure you pass it a value like this testforadmin.php?id=3

Post any errors that you get here.

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#28 almightyegg

almightyegg
  • Members
  • PipPipPip
  • Advanced Member
  • 791 posts
  • LocationEngland

Posted 25 October 2006 - 11:43 AM

thanks it worked perfectly, have started to tweak it now with other column values etc...
thanks again  ;D
Visit my Game - Under Construction

#29 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 25 October 2006 - 11:47 AM

OK, well I'm glad that it worked.  You could reduce the overhead even more by including a 'role' column in your database that designates whether the user is 'admin' or not...

This way you can do away with the $admin_ids array and use the value from the database to check if their admin or not.  Something like this...

<?php
if ($view3['role'] == "admin"){
   echo "{$view3['username']} is an administrator\n";
}
else {
   echo "{$view3['username']} is not an administrator\n";
}
?>

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#30 almightyegg

almightyegg
  • Members
  • PipPipPip
  • Advanced Member
  • 791 posts
  • LocationEngland

Posted 25 October 2006 - 11:52 AM

yes i may do that, i have that column already, but i had it when i couldn't even do
echo "Hello World!";
:D
Visit my Game - Under Construction




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users