Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 04-16-2005, 11:20 AM How to Verify Users
Junior Talker

Posts: 1
Trades: 0
I am trying to make a page where only admins can get. You can then check out the person profile and determine to verify them or not. The reason this is done manually is because its about a game, and if the enemies get in...Well I’m sure you can think. I have the admin page, only accessible by admins. I can output a verification table, but I cant update the database. Here is what my verification table looks like.



This is the following code that pertains to that.

PHP Code:
<?php        
        $not_verified 
mysql_query("SELECT * FROM users WHERE status = '0'") or die(mysql_error());
            
        print 
"<form name=\"verify\" method=\"post\" action=\"users.php\">
               <table width=\"500\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
                  <tr bgcolor=\"#990000\"> 
                <td width=\"100\"> <div align=\"center\"><font color=\"#CCCCCC\"><strong>Username</strong></font></div></td>
                <td width=\"100\"> <div align=\"center\"><font color=\"#CCCCCC\"><strong>StrikeAction</strong></font></div></td>
                <td width=\"100\"> <div align=\"center\"><font color=\"#CCCCCC\"><strong>Armysize</strong></font></div></td>
                <td width=\"30\"> <div align=\"center\"><font color=\"#CCCCCC\"><strong>Verify</strong></font></div></td>
                  </tr>"
;
        while(
$info mysql_fetch_array($not_verified)){
            
$userun $info['user'];
            
$userstatid "http://www.kingsofchaos.com/stats.php?id=".$info['statid'];
            
$usersa $info['strikeaction'];
            
$userarmysize $info['armysize'];
            
            print 
"<tr> 
                   <td width=\"100\"> 
                    <div align=\"right\"><a href=\"
$userstatid\" target=\"_blank\">$userun</a></div></td>
                      <td width=\"100\"> 
                     <div align=\"right\">
$usersa</div></td>
                    <td width=\"100\"> 
                   <div align=\"right\">
$userarmysize</div></td>
                   <td width=\"30\"> 
                   <div align=\"center\"> 
                     <input name=\"vusername['"
.$userun."']\" type=\"checkbox\" id=\"$userun\" value=\"1\">
                      </div>
                      </td>
                    </tr>"
;
        }
        print 
"  <tr bgcolor=\"#990000\">
                  <td width=\"100\" height=\"25\">&nbsp;</td>
                  <td width=\"100\" height=\"25\">&nbsp;</td>
                  <td width=\"100\" height=\"25\">&nbsp;</td>
                  <td width=\"40\" height=\"25\"> 
                    <div align=\"center\"> 
                  <input type=\"submit\" name=\"Submit\" value=\"Verify\" style=\"color:black; background-color:#CCCCCC; border-width:0px;\">
                  </div></td>
                  </tr>
                </table></form>"
;
                
        if(
$_POST){
            foreach(
$_POST['vusername'] as $vusername => $value){
                
mysql_query("UPDATE `users` SET `status` = 1 WHERE user = '".$vusername."' LIMIT 1") or die(mysql_error());
                echo 
$vusername;
            }
        }        
        
?>
My problem is that it never updates the database where status is to 1 with the selected username in the verification table. Any help would be great full; I have tried to post on several other forums, but no help. I hope you can all help me.
Incognito is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-17-2005, 02:34 PM
leavethisplace's Avatar
Ultra Talker

Posts: 297
Trades: 0
Incorrect use:
PHP Code:
mysql_query("UPDATE `users` SET `status` = 1 WHERE user = '".$vusername."' LIMIT 1") or die(mysql_error()); 
Correct use:
PHP Code:
$query "UPDATE users SET 
status = '1'
WHERE user = '
$vusername'";

$result mysql_query($query)
or die(
"Query failed: " mysql_error()); 
Tidy up your code, place mysql querys into variables before putting them into the mysql_query() function, this allows you to place variables easily into the argument, and use "" in variable raparounds where you're going to have further variables.

Happy families!
__________________
A lie gets halfway around the world before the truth has a chance to get its pants on. - Sir Winston Churchill

Please visit my sites:
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
leavethisplace is offline
Reply With Quote
View Public Profile
 
Old 04-18-2005, 07:29 AM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
I can't see anything wrong with the original query. The backticks are optional in mySQL unless a fieldname clashes with a mysql keyword (say you had a field called `where`). The 1 need not have quotes since it is a number, and $vusername is added correctly to the string.

I agree that the code given by leavethisplace is much tidier and easier to read.

I think your problem comes from your foreach. The values in the checkbox array are of the form 0=>user1 1=>user2 etc, so you need to change the foreach to something like
PHP Code:
foreach($_POST['vusername'] as $number => $vusername){ 
Then it ought to work.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Reply     « Reply to How to Verify Users
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.12361 seconds with 12 queries