TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-04-2010, 05:28 AM   #1 (permalink)
The Contributor
 
SaintIsaiah's Avatar
 
Join Date: Jan 2009
Posts: 48
Thanks: 5
SaintIsaiah is on a distinguished road
Default Problem with sql result echo

I'm modifying a CMS to create an if/else statement to prevent a journalist who is not an editor from seeing any articles except the ones they made. However, it seems that the code I made to get their usergroup ID is not getting the result to use for the if/else statement. I'm trying just to echo the user's group id to see if it just works first so I can continue finishing the code. Here's what I got.

PHP Code:
$usernamesql $userinfo['username']; //$userinfo['username'] is defined in another part of the page and already works

  
$getugroupid mysql_query("SELECT * FROM pam_users WHERE username = '.$usernamesql.'"); //Trying to select all of the user's info in the DB

$ugroupid mysql_fetch_array($getugroupid); //Trying to create an array to echo values from

echo '<center><h1>'$ugroupid['usergroupid'] .'</h1></center>';//'usergroupid' is the name of the column in the db containing that user's group id number 
However, it never shows the user's group id. Any idea what I'm doing wrong?

Last edited by SaintIsaiah : 04-04-2010 at 08:43 AM.
SaintIsaiah is offline  
Reply With Quote
Old 04-04-2010, 02:59 PM   #2 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Without seeing the database it's hard to tell. Have you tried the following?

php Code:
// Your code, then
echo '<pre>' . print_r( $ugroupid, TRUE ) . '</pre>';

// or simply

$result = mysql_query( sprintf( "SELECT usergroupid FROM pam_users WHERE username = '%s' LIMIT 1", $userinfo['username'] ) );
$ugroupid = mysql_result( $result );

Don't forget to double check your $userinfo array and make sure username is properly set as well.
delayedinsanity is offline  
Reply With Quote
Old 04-04-2010, 08:03 PM   #3 (permalink)
The Contributor
 
SaintIsaiah's Avatar
 
Join Date: Jan 2009
Posts: 48
Thanks: 5
SaintIsaiah is on a distinguished road
Default

Well I just got it working. Here's what I did:

PHP Code:
$usernamesql $userinfo['username'];

$getugroup $DB->query("SELECT * FROM {users} WHERE username = '".$usernamesql."'");

$ugroupids $DB->fetch_array($getugroup);

$ugroupid $ugroupids['usergroupid'];

echo 
$ugroupid
The $DB variable was already defined as well. I guess it was just a syntax error.

What I did was pretty much used an if/else statement to show what info a user is allowed to see based on what usergroup they're in.

PHP Code:
if (($ugroupid != '1') && ($ugroupid != '6') && ($ugroupid != '7') && ($ugroupid != '8'))  {

//Restricted Access

} else {

//Full Access


It works, but I was wondering how to make an if statement that will check all of those group id numbers at once, like an if array statement. That possible?
SaintIsaiah is offline  
Reply With Quote
Old 04-04-2010, 08:16 PM   #4 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

php Code:
if ( in_array( $ugroupid, array( 1, 6, 7, 8 ) ) ) {
//do stuff
}
delayedinsanity is offline  
Reply With Quote
Old 04-05-2010, 04:59 PM   #5 (permalink)
The Contributor
 
SaintIsaiah's Avatar
 
Join Date: Jan 2009
Posts: 48
Thanks: 5
SaintIsaiah is on a distinguished road
Default

Quote:
Originally Posted by delayedinsanity View Post
php Code:
if ( in_array( $ugroupid, array( 1, 6, 7, 8 ) ) ) {
//do stuff
}
Sweet, that works perfectly!
SaintIsaiah is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Advance Pagination Class Rendair Advanced PHP Programming 13 02-01-2013 11:08 AM
SQL comma problem vpopp MySQL & Databases 16 01-29-2013 12:27 PM
World of Warcraft Armory xml Grabber with cURL mortisimus Show Off 144 06-25-2012 12:34 PM
Mysql_fetch_array echo only 1 result CΛSTΞX General 5 03-12-2010 12:40 PM
MySql Add to favorites - almost functional - help micma909 MySQL & Databases 1 12-19-2009 08:18 PM


All times are GMT. The time now is 04:34 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design