• RSS
  • Twitter
  • FaceBook

Security Forums

Log in

FAQ | Search | Usergroups | Profile | Register | RSS | Posting Guidelines | Recent Posts

phpBB2 database output

Users browsing this topic:0 Security Fans, 0 Stealth Security Fans
Registered Security Fans: None
Post new topic   Reply to topic   Printer-friendly version    Networking/Security Forums Index -> Databases

View previous topic :: View next topic  
Author Message
razta
Just Arrived
Just Arrived


Joined: 12 Nov 2005
Posts: 2
Location: 127.0.0.1

Offline

PostPosted: Sat Aug 12, 2006 5:02 pm    Post subject: phpBB2 database output Reply with quote

My PHP + MYSQL skills are minimal however ive tried to have a go at it but I cant seem to get it to work. What I want is to select how many users have registerd to my phpBB2 forums and output it to a PHP page.

Heres the code I have so far:
Code:

<?
$username="username";
$password="password";
$database="phpBB";
$host="mysql.mysite.com";


mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$sql = "SELECT count(user_id) as usercount
   FROM " . USERS_TABLE . "";

$result=mysql_query($sql); 

mysql_close();

echo $result;
?>


The page is presented with no errors however the $result is not outputed to the page either, any know where Im going wrong?
Back to top
View user's profile Send private message
Giro
New Member
New Member


Joined: 25 Mar 2004
Posts: 22
Location: England

Offline

PostPosted: Sat Aug 12, 2006 9:59 pm    Post subject: Reply with quote

Code:

<?php
[...]
$result=mysql_query($sql);
[...]
echo $result;
?>


The problem here is that you are trying to use the variable result as if it held an integer. If you look at the PHP docs you will notice that it holds a 'resource' (see this link, under heading Return values).

You need to either use mysql_fetch_row or mysql_fetch_array to obtain the actual value from the row/s.
Back to top
View user's profile Send private message
razta
Just Arrived
Just Arrived


Joined: 12 Nov 2005
Posts: 2
Location: 127.0.0.1

Offline

PostPosted: Mon Aug 14, 2006 12:14 pm    Post subject: Reply with quote

Thank you for your reply. Got it working finally with the following code.

Code:
<?
$username="username";
$password="password";
$database="phpBB";
$host="mysql1.mysite.com";

mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$sql = "SELECT count(user_id) as usercount
   FROM phpbb_users";

if( !($result = mysql_query($sql)) )
echo '<b>Query: </b>' . $sql . '<br /><b>Status: </b><font color="red">Error running query (' . mysql_error() . ')</font><br /><br />';

while( $row = mysql_fetch_array($result) )
echo $row['usercount'] - 1; // So as to not count the anonymous user

mysql_close();
?>
Back to top
View user's profile Send private message
razta
Just Arrived
Just Arrived


Joined: 12 Nov 2005
Posts: 2
Location: 127.0.0.1

Offline

PostPosted: Mon Aug 14, 2006 1:16 pm    Post subject: Reply with quote

Figured the usercount code however cant figure out the query for the newest registerd username. Any one help?

Code:
<?
$username="username";
$password="password";
$database="phpBB";
$host="mysql1.mysite.com";

mysql_connect($host,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$sql = "SELECT user_id, username as usercount
            FROM  phpbb_users
            WHERE user_id <> Anonymous
            ORDER BY user_id DESC
            LIMIT 1";

if( !($result = mysql_query($sql)) )
echo '<b>Query: </b>' . $sql . '<br /><b>Status: </b><font color="red">Error running query (' . mysql_error() . ')</font><br /><br />';

while( $row = mysql_fetch_array($result) )
echo $row['usercount']; // So as to not count the anonymous user

mysql_close();
?>


Got it working! Changed: "Anonymous" to: "-1"
Back to top
View user's profile Send private message
santium
Just Arrived
Just Arrived


Joined: 25 Oct 2006
Posts: 0


Offline

PostPosted: Sat Nov 04, 2006 3:54 pm    Post subject: Reply with quote

You can use the mysql_num_rows function in PHP to get the number of registered users.
Try this
Code:
<?php
$username = "myusername";
$password = "mypassword";
$database = "mydatabase";
$host = "localhost";

mysql_connect($host, $username, $password);
@mysql_select_db($database) or die("Problem selecting database.");

$sql_newestuser = "SELECT * FROM phpbb_users WHERE user_id > -1 ORDER BY user_id DESC LIMIT 1";
$do_newestuser = mysql_query($sql_newestuser);

$sql_usercount = "SELECT * FROM phpbb_users WHERE user_id > -1";
$do_usercount = mysql_query($sql_usercount);
while ($result = mysql_fetch_array($do_newestuser))
echo "Newest User: ".$result['username'];
echo "Total users: ".mysql_num_rows($do_usercount);
?>


As you can tell, it displays both the newest username and the total number of users. (While there is an easier way to do what this code does, this is just a rough example.
Back to top
View user's profile Send private message
Display posts from previous:   

Post new topic   Reply to topic   Printer-friendly version    Networking/Security Forums Index -> Databases All times are GMT + 2 Hours
Page 1 of 1


 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Community Area

Log in | Register