Jump to content

[SOLVED] Selecting Tables from a using sessions


Deanznet

Recommended Posts

Hey Their Im working on this game but im having trouble. I can select information from a 1 specific user but i really cant figure out how to select it using the session.

 

<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);

//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//
// Sorry , only logged users ...
if ( !$userdata['session_logged_in'] )
{
$redirect = "traded.$phpEx";
$redirect .= ( isset($user_id) ) ? '&user_id=' . $user_id : '';
header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true));
}

if($userdata['session_logged_in'])
{
$database="N/A";
mysql_connect ("N/A", "N/A", "N/A"); 
@mysql_select_db($database) or die( "Unable to select database");
$result = mysql_query( "select username,user_points from phpbb_users where username='cablekid'" )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
print "There are $num_rows records.<P>";
print "<table width=200 border=1>\n";
while ($get_info = mysql_fetch_row($result)){
print "<tr>\n";
foreach ($get_info as $field)
print "\t<td><font face=arial size=1/>$field</font></td>\n";
print "</tr>\n";
}
print "</table>\n";

echo('Hi' . $userdata['username'] . '!');

}
else
{
echo('You are a guest');
}

?>

 

 

See here

 

I thought it would be something like this

$result = mysql_query( "select username,user_points from phpbb_users where $userdata['username']'" )

 

But that dosent work either..

 

Any help would be great.

Link to comment
Share on other sites

If you are building within the phpBB environment, you should not have to do all of this work... You have missed some included files which will allow you to use their MySQL abstraction layer. You won't have to 'connect' and all that stuff, and you'll have the object $db to make SQL queries with.

 

Is this a phpBB2 installation? If so, I can provide you with the right start-up includes to access their kung-foo.

 

PhREEEk

Link to comment
Share on other sites

Im using trying to make a phpbb game kinda.. Well its going to be all based on phpbb..

 

 

I have phpbb board with the arcade and cash mod.. So for people to make games they either post or play the arcade. Then they get money they can spend in the game.

 

I dont know how to display the cash they have in the database thats what is what i was trying to do

Link to comment
Share on other sites

Ok, I have 2 things to try with your script. Run them separately, and post the results separately.

 

Test one:

<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);

//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//
// Sorry , only logged users ...
echo "<pre>";
print_r($userdata);
die("</pre>");
if ( !$userdata['session_logged_in'] )
{
$redirect = "traded.$phpEx";
$redirect .= ( isset($user_id) ) ? '&user_id=' . $user_id : '';
header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true));
}

if($userdata['session_logged_in'])
{
$database="N/A";
mysql_connect ("N/A", "N/A", "N/A"); 
@mysql_select_db($database) or die( "Unable to select database");
$result = mysql_query( "select username,user_points from phpbb_users where username='cablekid'" )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
print "There are $num_rows records.<P>";
print "<table width=200 border=1>\n";
while ($get_info = mysql_fetch_row($result)){
print "<tr>\n";
foreach ($get_info as $field)
print "\t<td><font face=arial size=1/>$field</font></td>\n";
print "</tr>\n";
}
print "</table>\n";

echo('Hi' . $userdata['username'] . '!');

}
else
{
echo('You are a guest');
}

?>

 

Test two:

<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);

//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//
// Sorry , only logged users ...
$sql = "SELECT * FROM `phpbb_users`";
if ( !result= $db->sql_query($sql) ) {
    die('MySQL Error');
}
$num_rows = $db->sql_numrows($result);
echo "$num_rows Users found!";
die();
if ( !$userdata['session_logged_in'] )
{
$redirect = "traded.$phpEx";
$redirect .= ( isset($user_id) ) ? '&user_id=' . $user_id : '';
header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true));
}

if($userdata['session_logged_in'])
{
$database="N/A";
mysql_connect ("N/A", "N/A", "N/A"); 
@mysql_select_db($database) or die( "Unable to select database");
$result = mysql_query( "select username,user_points from phpbb_users where username='cablekid'" )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
print "There are $num_rows records.<P>";
print "<table width=200 border=1>\n";
while ($get_info = mysql_fetch_row($result)){
print "<tr>\n";
foreach ($get_info as $field)
print "\t<td><font face=arial size=1/>$field</font></td>\n";
print "</tr>\n";
}
print "</table>\n";

echo('Hi' . $userdata['username'] . '!');

}
else
{
echo('You are a guest');
}

?>

 

PhREEEk

Link to comment
Share on other sites

First one shows

 

Array
(
    [user_id] => 3
    [user_active] => 1
    [username] => Myusername
    [user_password] => md5hash
    [user_session_time] => 1193232535
    [user_session_page] => 0
    [user_lastvisit] => 1196121530
    [user_regdate] => 1152063005
    [user_level] => 1
    [user_posts] => 237
    [user_timezone] => -4.00
    [user_style] => 5
    [user_lang] => english
    [user_dateformat] => D M d, Y g:i a
    [user_new_privmsg] => 0
    [user_unread_privmsg] => 0
    [user_last_privmsg] => 1195881794
    [user_login_tries] => 0
    [user_last_login_try] => 0
    [user_emailtime] => 
    [user_viewemail] => 0
    [user_attachsig] => 1
    [user_allowhtml] => 0
    [user_allowbbcode] => 1
    [user_allowsmile] => 1
    [user_allowavatar] => 1
    [user_allow_pm] => 1
    [user_allow_viewonline] => 1
    [user_notify] => 0
    [user_notify_pm] => 1
    [user_popup_pm] => 1
    [user_rank] => 1
    [user_avatar] => Comics/008.jpg
    [user_avatar_type] => 3
    [user_email] => dino_x9@hotmail.com
    [user_icq] => 
    [user_website] => 
    [user_from] => 435 south.. wait why am i telling you this?
    [user_sig] => 
    [user_sig_bbcode_uid] => 
    [user_aim] => Soul+Reaper89
    [user_yim] => 
    [user_msnm] => dino_x9@hotmail.com
    [user_occ] => 
    [user_interests] => 
    [user_actkey] => 
    [user_newpasswd] => 
    [user_birthday] => 999999
    [user_next_birthday_greeting] => 0
    [user_allowdesc] => 0
    [user_allowmoddesc] => 0
    [user_showdescriptions] => 0
    [user_showtooltips] => 0
    [user_tooltips_parse] => 1
    [user_tooltips_static] => 0
    [user_toolimg_width] => 1
    [user_toolimg_height] => 1
    [user_show_quickreply] => 1
    [user_quickreply_mode] => 1
    [user_open_quickreply] => 1
    [games_block_pm] => 1
    [user_troll] => 0
    [user_adr_ban] => 0
    [user_cell_time] => 0
    [user_cell_time_judgement] => 0
    [user_cell_caution] => 0
    [user_cell_sentence] => 
    [user_cell_enable_caution] => 0
    [user_cell_enable_free] => 0
    [user_cell_celleds] => 0
    [user_cell_punishment] => 0
    [user_points] => 45093
    [arcade_banned] => 0
    [session_id] => be3214321312c4526af27ea12312406
    [session_user_id] => 3
    [session_start] => 119122318
    [session_time] => 1196132535
    [session_ip] => 4514322cd
    [session_page] => 0
    [session_logged_in] => 1
    [session_admin] => 0
)

 

Test 2 Showed My Users

 

you dont need the Db Connection information works without it.

 

 

Link to comment
Share on other sites

Ok, looks like you're all setup...

 

>I dont know how to display the cash they have in the database thats what is what i was trying to do

 

If that's user_points, then phpBB has already populated that into $userdata. If you refer to the print_r dump, you'll see every user stat that is available to you at any point, on any page. You don't need to use a separate session.

 

so:

 

<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);

//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//
// Sorry , only logged users ...
if ( !$userdata['session_logged_in'] ) {
    $redirect = "traded.$phpEx";
    $redirect .= ( isset($user_id) ) ? '&user_id=' . $user_id : '';
    header('Location: ' . append_sid("login.$phpEx?redirect=$redirect", true));
}

if( $userdata['session_logged_in'] ) {
    echo "<table width=\"200\" border=\"1\">
  <tr>
    <td><font face=arial size=\"1\">$userdata['user_points']</font></td>
  </tr>
</table>
<p>
Hi $userdata['username']!</p>";
}

?>

 

Should get the job done...

 

PhREEEk

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.