Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9
This is the forum to discuss the Wrox book PHP and MySQL: Create-Modify-Reuse by Timothy Boronczyk, Martin E. Psinas; ISBN: 9780470192429
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: PHP and MySQL: Create-Modify-Reuse ISBN: 978-0-470-19242-9 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 19th, 2012, 09:41 AM
Authorized User
Points: 36, Level: 1
Points: 36, Level: 1 Points: 36, Level: 1 Points: 36, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2012
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 1 & 2 - Issue with double digit option values...

Hi folks,

This isn't exactly in the book, but since I was extending the original code from this book to make an admin panel based on the user class from chapter one and two, I was hoping someone on here could help me out.

I modified the user class, since for the time being I wasn't planning on a forum (although that might change in the future), to create admins and the like as such:

PHP Code:
class User
{
    
// Permission levels.
    
const HELPER 2;
    const 
MODERATOR 4;
    const 
VICE_ADMIN 8;
    const 
ADMIN 16;
// etc...
?> 
Now my problem occurs on my admin panel. Whenever I try to make an admin (value = 16) it returns a value of 1. In fact I've tried the code I use on other things as well as experiments and anything in double digits or greater is returning 1 (might return other single digit numbers as well - I can test further if necessary). I originally had the options hardcoded into the selection box. I then tried making a MySQL table with the values to see if it was something I may have overlooked and the same result.

The code for the admin panel:
PHP Code:
<?php

// Include shared code.
include_once 'admin_header.php';


// Generate user information form.
$user User::getById($_SESSION['user_id']);
if (
$user->permission User::ADMIN)
{
    echo 
'<h3>Administrator Panel</h3>';
    
// User Permission Panel
    
ob_start();
    
?>
<div id="wrapper">
<div id="admin_user_panel">
    <form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post">
            <table>
                <caption style="text-align: left;">Manage User Rights</caption>
                    <tr>
                            <td><label for="username">Username:</label></td>
                            <td><select name="username" id="username"><?php
                                                    $query 
sprintf('SELECT user_id, username FROM %suser ORDER BY username ASC'DB_TBL_PREFIX);
                                                    
$result mysql_query($query$GLOBALS['DB']);
                                                    echo 
'<option value="-1">Please Select a User</option>';
                                                    while (
$row mysql_fetch_assoc($result))
                                                    {
                                                        echo (
'<option value="' $row['user_id'] . '">' $row['username'] . '</option>');
                                                    }
                                                    
?></select></td>
                    </tr>
                    <tr>
                            <td><label for="permissions">Permissions:</label></td>
                            <td><select name="permissions" id="permissions"><?php
                                                    $query 
sprintf('SELECT permission, permission_description FROM %spermissions ORDER BY permission ASC'DB_TBL_PREFIX);
                                                    
$result mysql_query($query$GLOBALS['DB']);
                                                    echo 
'<option value="-1">Please Select Role</option>';
                                                    while (
$row mysql_fetch_assoc($result))
                                                    {
                                                        echo (
'<option value="' $row['permission'] . '">' $row['permission_description'] . '</option>');
                                                    }
                                                    
?>                                    
                                </select></td>
                    </tr>
                    <tr>
                            <td> </td>
                            <td align="right"><input type="submit" value="Update"/></td>
                            <td><input type="hidden" name="submitted" value="1"/></td>
                    </tr>
                    <tr>
                    </tr>
            </table>
    </form>
    <form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post">
            <table>
                <caption style="text-align: left;">Ban User</caption>
                    <tr>
                            <td><label for="ban">Ban:</label></td>
                            <td><select name="ban" id="ban"><?php
                                                    $query 
sprintf('SELECT user_id, username FROM %suser ORDER BY username ASC'DB_TBL_PREFIX);
                                                    
$result mysql_query($query$GLOBALS['DB']);
                                                    echo 
'<option value="-1">Please Select a User to Ban</option>';
                                                    while (
$row mysql_fetch_assoc($result))
                                                    {
                                                        echo (
'<option value="' $row['user_id'] . '">' $row['username'] . '</option>');
                                                    }
                                                    
?></select></td>
                    </tr>
                    <tr>
                            <td> </td>
                            <td align="right"><input type="submit" value="Update"/></td>
                            <td><input type="hidden" name="submitted1" value="1"/></td>
                    </tr>
                    <tr>
                    </tr>
            </table>
    </form>
    <form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="post">
            <table>
                <caption style="text-align: left;">Warn User</caption>
                    <tr>
                            <td><label for="warn">Warn:</label></td>
                            <td><select name="warn" id="warn"><?php
                                                    $query 
sprintf('SELECT user_id, username FROM %suser ORDER BY username ASC'DB_TBL_PREFIX);
                                                    
$result mysql_query($query$GLOBALS['DB']);
                                                    echo 
'<option value="-1">Please Select a User to Warn</option>';
                                                    while (
$row mysql_fetch_assoc($result))
                                                    {
                                                        echo (
'<option value="' $row['user_id'] . '">' $row['username'] . '</option>');
                                                    }
                                                    
?></select></td>
                    </tr>
                    <tr>
                            <td> </td>
                            <td align="right"><input type="submit" value="Update"/></td>
                            <td><input type="hidden" name="submitted2" value="1"/></td>
                    </tr>
                    <tr>
                    </tr>
            </table>
    </form>
</div>
<div id="admin_user_view">
    <table>
        <caption style="text-align: right;">Banned Users</caption>
            <tr>
            </tr>
                    <tr><td>User ID</td><td>Username</td></tr>            
                    <?php
                                            $query 
sprintf('SELECT user_id, banned FROM %sbanned WHERE banned = %d'DB_TBL_PREFIX1);
                                            
$result mysql_query($query$GLOBALS['DB']);
                                            while (
$row mysql_fetch_assoc($result))
                                            {
                                                echo 
'<tr><td>' $row['user_id'] . '</td><td>';
                                                
$query1 sprintf('SELECT username FROM %suser WHERE user_id = %d'DB_TBL_PREFIX$row['user_id']);
                                                
$result1 mysql_query($query1$GLOBALS['DB']);
                                                
$row1 mysql_fetch_assoc($result1);
                                                echo 
$row1['username'] . '</td></tr>';
                                            }
                                            
?>
            <tr>
            </tr>
    </table><br /><br />
    <table>
        <caption style="text-align: right;">Warned Users</caption>
            <tr>
            </tr>
                    <tr><td>User ID</td><td>Username</td></tr>            
                    <?php
                                            $query 
sprintf('SELECT user_id, warned FROM %sbanned WHERE warned = %d'DB_TBL_PREFIX1);
                                            
$result mysql_query($query$GLOBALS['DB']);
                                            while (
$row mysql_fetch_assoc($result))
                                            {
                                                echo 
'<tr><td>' $row['user_id'] . '</td><td>';
                                                
$query1 sprintf('SELECT username FROM %suser WHERE user_id = %d'DB_TBL_PREFIX$row['user_id']);
                                                
$result1 mysql_query($query1$GLOBALS['DB']);
                                                
$row1 mysql_fetch_assoc($result1);
                                                echo 
$row1['username'] . '</td></tr>';
                                            }
                                            
?>
            <tr>
            </tr>
    </table>
</div>
</div>
    <?php 
    $form 
ob_get_clean();

    
// Show the form if this is the first time the page is viewed.
    
if (!isset($_POST['submitted']) && !isset($_POST['submitted1']) && !isset($_POST['submitted2']))
    {
            
$GLOBALS['TEMPLATE']['content'] = $form;
    }
    
// Otherwise process the incoming data.
    
else if (isset($_POST['submitted']))
    {
        
$user_id $_POST['username']['user_id'];
        
$permission $_POST['permissions']['permission'];
        
        
$query sprintf("UPDATE %suser SET permission = %d WHERE user_id = '$user_id'"DB_TBL_PREFIX$permission);
        
mysql_query($query$GLOBALS['DB']);
        echo 
mysql_error();

        
$GLOBALS['TEMPLATE']['content'] = '<p><strong>The user\'s status has been modified successfully.</strong></p>';

    }
    else if (isset(
$_POST['submitted1']))
    {
        
$user_id $_POST['ban']['user_id'];
        
        
$query sprintf("INSERT INTO %sbanned (user_id, banned, warned) VALUES (%d, %d, %d)"DB_TBL_PREFIX$user_id10);
        
mysql_query($query$GLOBALS['DB']);
        echo 
mysql_error();

        
$GLOBALS['TEMPLATE']['content'] = '<p><strong>The user\'s status has been modified successfully.</strong></p>';

    }
    else if (isset(
$_POST['submitted2']))
    {
        
$user_id $_POST['warn']['user_id'];
        
        
$query sprintf("INSERT INTO %sbanned (user_id, banned, warned) VALUES (%d, %d, %d)"DB_TBL_PREFIX$user_id01);
        
mysql_query($query$GLOBALS['DB']);
        echo 
mysql_error();

        
$GLOBALS['TEMPLATE']['content'] = '<p><strong>The user\'s status has been modified successfully.</strong></p>';

    }
}
else
{
    
header('HTTP/1.0 401 Authorization Error');
    
ob_start();
    
?>
    <script type="text/javascript">
    window.seconds = 5;
    window.onload = function()
    {
        if (window.seconds != 0)
        {
            document.getElementById('secondsDisplay').innerHTML = '' + window.seconds + ' second' + ((window.seconds > 1) ? 's' : '');
            window.seconds--;
            setTimeout(window.onload, 1000);
        }
        else
        {
            window.location = '../index.php';
        }
    }
    </script>
    <?php
    $GLOBALS
['TEMPLATE']['extra_head'] = ob_get_contents();
    
ob_clean();
    
?>
    <p>The credentials you have supplied do not authorize you for access.</p>
    <p><strong>You will be redirected to the main page in <span id="secondsDisplay">5 seconds</span>.</strong></p>
    <p>If you are not automatically redirected there, please click on the following link: <a href="../index.php">Home</a></p>
    
    <?php
    $GLOBALS
['TEMPLATE']['content'] = ob_get_clean();
}



// Display the page
include 'templates/admin_template.php';
?>
Any help would be greatly appreciated
Reply With Quote
  #2 (permalink)  
Old April 26th, 2012, 06:46 AM
Authorized User
Points: 36, Level: 1
Points: 36, Level: 1 Points: 36, Level: 1 Points: 36, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2012
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've done some more testing, and it seems no matter what value I give the option field (be it numbers or letters) it always returns the first number or letter of the value...

I honestly am running out of ideas for testing this further... Some help would be greatly appreciated...
Reply With Quote
  #3 (permalink)  
Old April 26th, 2012, 01:32 PM
Authorized User
Points: 36, Level: 1
Points: 36, Level: 1 Points: 36, Level: 1 Points: 36, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2012
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default [SOLVED] Chapter 1 & 2 - Issue with double digit option values...

Finally managed to solve the problem...

I changed:
PHP Code:
$user_id $_POST['username']['user_id'];
        
$permission $_POST['permissions']['permission']; 
to:
PHP Code:
$user_id $_POST['username'];
        
$permission $_POST['permissions']; 
and it seems to be taking double digit values so far...
If anyone can explain to me why removing what I did manages to solve this issue I would be most greatful!!
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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Double display of html:select option cesarv JSP Basics 6 July 20th, 2009 05:49 AM
Double values andyetisay Java Basics 1 February 4th, 2008 11:15 PM
option values hastikeyvan Dreamweaver (all versions) 3 October 13th, 2005 01:19 AM
option values hastikeyvan Dreamweaver (all versions) 6 September 23rd, 2005 11:56 PM
Option Button & Macro jvanhalderen Excel VBA 2 November 28th, 2004 03:09 PM



All times are GMT -4. The time now is 02:32 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.