Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
  #1  
Old 01-30-2004, 02:06 PM
ap0c's Avatar
ap0c ap0c is offline
 
Join Date: Mar 2003
Posts: 210
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default writing an sql query

2.3.x version
What this script is supposed to do is allow a member of the view only usergroup the right to post on the forums after this script is run. When a user registers they are placed in a view only usergroup (9.)
Once a user decides they want to post, they click on a link that runs this script.

This script was written to check that users ipaddress against those in the registered usergroup, post. ipaddress and the banned usergroup.(The banned usergroup(8) check isnt in place as I'm not sure how to add that to this query)

This script doesnt cause any mqsql errors, but also doesnt work. Anyone know what I'm doing wrong?

PHP Code:
 require("./global.php");
global 
$DB_site,$session,$ipaddress;
   print 
"Checking for Posting Permissions<br>";
$userid $bbuserinfo['userid'];
   print 
"$userid<br>";
   print 
"$ipaddress<br>";

    
$tmpipcheck=$ipaddress
$result
=$DB_site->query("SELECT user.*,post.* FROM user LEFT JOIN post on user.id = post.userid WHERE usergroupid=2 AND ipaddress='$tmpipcheck'");
    if (
$myrows=mysql_fetch_row($result));{
        }WHILE (
$myrows=mysql_fetch_row($result));{
            eval(
"standarderror(\"".gettemplate("error_sorrynoposting")."\");");
            exit;
}Else{
                  
If (
$bbuserinfo['usergroupid']==9){  
          
$DB_site->query("UPDATE user SET usergroupid=2  WHERE userid='$userid'");
 eval(
"standarderror(\"".gettemplate("error_youcanpostnow")."\");"); 
 }else{
 eval(
"standarderror(\"".gettemplate("error_alreadyregistered")."\");");
           exit;
     }
}

mods, if this thread is in the wrong place, please move it, just let me know where
Reply With Quote
  #2  
Old 01-30-2004, 02:29 PM
Lesane's Avatar
Lesane Lesane is offline
 
Join Date: Oct 2001
Location: The Netherlands
Posts: 1,149
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

There can be more problems but change this:

user.id = post.userid

to:

user.userid = post.userid
Reply With Quote
  #3  
Old 01-30-2004, 02:54 PM
Natch's Avatar
Natch Natch is offline
 
Join Date: Nov 2002
Location: Australia
Posts: 851
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm not sure this looks right ...
PHP Code:
    if ($myrows=mysql_fetch_row($result));{
        }WHILE 
Looks to me like you are starting and ending your if prior to any result of the if being true ...
Reply With Quote
  #4  
Old 01-30-2004, 04:36 PM
g-force2k2 g-force2k2 is offline
 
Join Date: Mar 2002
Location: Everywhere you wanna be..
Posts: 1,608
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Maybe something like this would work better? Also includes checking the banned usergroup, hopefully it helps or gives you some ideas.

PHP Code:
if ( $chk $DB_site->query_first "SELECT userid, usergroupid FROM user WHERE ipaddress='$ipaddress' ) ) :
    if ( 
$chk['usergroupid'] == 8 ) :
        //banned error here
    elseif ( 
$chk['usergroupid'] == 2 ) :
        //already registered error
    elseif ( 
$chk['usergroupid'] == 9 ) :
        
$DB_site->query ( "UPDATE user SET usergroupid=2 WHERE userid=$chk[userid]" ) ;
        //redirect here
    endif ;
endif ; 
Cheers,
g-force2k2
Reply With Quote
  #5  
Old 01-30-2004, 09:18 PM
ap0c's Avatar
ap0c ap0c is offline
 
Join Date: Mar 2003
Posts: 210
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by g-force2k2
Maybe something like this would work better? Also includes checking the banned usergroup, hopefully it helps or gives you some ideas.





Cheers,
g-force2k2
that looks really good! I'll give it a try
thanks
Reply With Quote
  #6  
Old 01-31-2004, 06:15 AM
ap0c's Avatar
ap0c ap0c is offline
 
Join Date: Mar 2003
Posts: 210
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I had to add an else to the final check because the registered template wouldnt show up when it was placed under the registered users check
PHP Code:
    elseif ( $chk['usegroupid'] == ) :
    
      elseif ( 
$chk['usergroupid'] == ) :
        
$DB_site->query "UPDATE user SET usergroupid=2 WHERE userid=$chk[userid]) ;
        eval(
"standarderror(\"".gettemplate("error_youcanpostnow")."\");");//redirect here
        
else :
        eval(
"standarderror(\"".gettemplate("error_sorrynoposting")."\");"); //already registered error 
other than that it works perfectly.

Thanks again.

Now to add the post check, which will be harder since it cant be checked by the usergroupid
Reply With Quote
  #7  
Old 01-31-2004, 06:42 AM
g-force2k2 g-force2k2 is offline
 
Join Date: Mar 2002
Location: Everywhere you wanna be..
Posts: 1,608
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by ap0c
I had to add an else to the final check because the registered template wouldnt show up when it was placed under the registered users check

other than that it works perfectly.

Thanks again.

Now to add the post check, which will be harder since it cant be checked by the usergroupid
Actually I updated my code had a spelling error for the variable usergroupid so the error should eval where I had intended it too. If you want to try matching it against the post ipaddress to then you can do.

PHP Code:
if ( $chk $DB_site->query_first "
        SELECT userid, usergroupid
        FROM user 
        LEFT JOIN post USING (userid)
        WHERE user.ipaddress='
$ipaddress' AND post.ipaddress='$ipaddress'" ) ) : 
    if ( 
$chk['usergroupid'] == ) : 
        
// banned error here 
    
elseif ( $chk['usergroupid'] == ) : 
        
// already registered error 
    
elseif ( $chk['usergroupid'] == ) :     
        
$DB_site->query "UPDATE user SET usergroupid=2 WHERE userid=$chk[userid]) ; 
            
// redirect here 
        
endif ; 
elseif ( 
$chk['userid'] ) :
    
// user exists just hasn't posted or current ipaddress doesn't match the posted one?
    
if ( $chk['usergroupid'] == ) :
        
// banned error 
    
elseif ( $chk['usergroupid'] == ) :
        
// already registered, but haven't posted? error
    
elseif ( $chk['usergroupid'] == ) :
        
$DB_site->query "UPDATE user SET usergroupid=2 WHERE userid=$chk[userid]) ; 
            
// redirect here 
        
endif ; 
else :
    
// failed check perhaps current ipaddres isn't the one they registered with?
    // don't know if vb3 updates ipaddress field with each visit so... check to see if user actually exists!
    
if( !$chk2 $DB_site->query_first "SELECT usergroupid FROM user WHERE userid=$bbuserinfo[userid]) ) :
        
// user isn't registered
        // register redirect or need to register error?
    
else :
        
// user exists ipaddress field is invalid perhaps update now?
        
if ( $chk2['usergroupid'] == ) :
            
// already registered error 
        
elseif ( $chk2['usergroupid'] == ) :
            
// banned error
        
elseif ( $chk2['usergroupid'] == ) :
            
// update from viewed usergroup to one that can post.
            
$DB_site->query "UPDATE user SET usergroupid=2 WHERE userid=$chk[userid]) ; 
                
// redirect here 
        
endif ;
    endif ;
endif ; 
There's alot to think about when using such code, then again I would probably do it an entirely different way. Hope this gives you some ideas.

Cheers,
g-force2k2
Reply With Quote
  #8  
Old 01-31-2004, 02:45 PM
ap0c's Avatar
ap0c ap0c is offline
 
Join Date: Mar 2003
Posts: 210
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

it was late, I didnt notice the usergroupid was spelled wrong

Right now all these checks are done manually, which takes quite a bit of time on certain days. I'm trying to figure out a way to make it automatic so the other admins can spend the time on something else.

I figure, a user presses a button which links to this script, runs it, the account is approved or not. Since the forum this will run on isn't going to be updated to vb3, a cron job probably wouldnt work, or be hard to set up with 2.x.x. So I thought this would be the best way. There are about 20-25,000 members in the view only group right now. Some people can wait a year or more before deciding they want to post.
Reply With Quote
  #9  
Old 02-01-2004, 04:16 PM
ap0c's Avatar
ap0c ap0c is offline
 
Join Date: Mar 2003
Posts: 210
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm running into an error running the first query
PHP Code:
 Invalid SQLSELECT useridusergroupid FROM user LEFT JOIN post USING (useridWHERE user.ipaddress='xx.xxx.xx.xx' AND post.ipaddress='xx.xxx.xx.xx'
mysql errorColumn'userid' in field list is ambiguous
mysql error number
1052 
changed ipaddress to xx.

using user.userid gave a 1064 error
Reply With Quote
  #10  
Old 02-01-2004, 04:25 PM
g-force2k2 g-force2k2 is offline
 
Join Date: Mar 2002
Location: Everywhere you wanna be..
Posts: 1,608
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by ap0c
I'm running into an error running the first query
PHP Code:
 Invalid SQLSELECT useridusergroupid FROM user LEFT JOIN post USING (useridWHERE user.ipaddress='xx.xxx.xx.xx' AND post.ipaddress='xx.xxx.xx.xx'
mysql errorColumn'userid' in field list is ambiguous
mysql error number
1052 
Try changing:

PHP Code:
       SELECT useridusergroupid 
To

PHP Code:
       SELECT user.useridusergroupid 
Regards,
g-force2k2
Reply With Quote
Reply

Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:13 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.08662 seconds
  • Memory Usage 2,297KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (9)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete