SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Anyone familiar with Smarty?

    I'm looking at a problem for someone and I can't quite see where the problem lies (within the code). It's part of the Admin utility and the error occurs when trying to Change Role for a user.

    The form loads and I select the appropriate setting (e.g. Normal User). The form looks like below ...

    Code:
    <form action="http://www.address.com/admin/chrole/" method="POST">
    
    <input type="hidden" name="id" value="14">
    <select name="role">
     <option value="2">Normal user
     <option value="3">Trusted user
     <option value="4">Comments moderator
     <option value="5">Global moderator
     <option value="10">Admin
    </select> <input type="submit">
    </form>
    As you can see, the id and role are both present in the form. When I click on submit then the page that loads is http://www.address.com/admin/chrole/ but it only shows the following error message ...

    Code:
    Cannot execute specified query: SELECT * FROM users WHERE id =
    ... which suggests that the id value has been lost.

    I tried changing POST to GET and see that the id and role values do indeed get forwarded to the page, so I don't understand this.

    If anyone is a Smarty guru and can give any pointers then it would be appreciated.

    Ian Anderson
    www.siteguru.co.uk

  2. #2
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Well, as I see, this is not a smarty related question.
    If you do a var_dump($_POST) on http://www.address.com/admin/chrole/, what do you get?
    -- Jelena --

  3. #3
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    It gives ...

    Code:
    array(2) { ["id"]=>  string(2) "14" ["role"]=>  string(1) "2" }
    ... which looks correct. It seems to me that maybe the wrong code is being executed. Could it be a mod_rewrite issue? I notice .htaccess has the following in the public_html folder ...

    Code:
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^/css/
    RewriteCond %{REQUEST_URI} !^/ad/
    RewriteCond %{REQUEST_URI} !^/d/
    RewriteCond %{REQUEST_URI} !^/images/
    RewriteCond %{REQUEST_URI} !^/geo/
    RewriteRule   ^(.*)$  ./x/index.php?q=$1  [PT]
    ... but in folder where the admin page is located (not one of the above) the .htaccess file has ...

    Code:
    RewriteEngine off
    Ian Anderson
    www.siteguru.co.uk

  4. #4
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hm, strange, it should work. Try without main htaccess and see if it'll work. It seems that htaccess in subfolder is not working

    Try to add:
    Code:
    AllowOverride All
    in main htaccess file
    -- Jelena --

  5. #5
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    If I put that in either .htaccess then I get a 500 error. If I delete the main .htaccess then I get a 404 error.

    Thanks for trying to help, but this is really puzzling me.

    Edit: What's the significance of the [PT] bit? It doesn't seem to make any difference whether it is there or not.
    Ian Anderson
    www.siteguru.co.uk

  6. #6
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    I'm not sure what the PT means, but try adding ',QSA' to it (without quotes, between the [ and ])

    That should append the querystring to the rewritten address.

  7. #7
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Tried it but makes no difference. (And given that the form POSTs I didn't really expect it to).

    This is really puzzling me.
    Ian Anderson
    www.siteguru.co.uk

  8. #8
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    Actually, it wouldn't make a difference anyway, as the Rewrite engine is off in the admin directory.

    Can you post the code where you construct the SQL query?

  9. #9
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Immerse
    Actually, it wouldn't make a difference anyway, as the Rewrite engine is off in the admin directory.
    That was my initial thought, but if I delete the .htaccess file (or just empty it) in the folder holding the admin file then a 500 error is thrown. So that rule needs to be there.

    Also, the POST data is being received by the admin page - that's why I am really puzzled. I would love to show you the code where the SQL is constructed, but that's the problem - at the moment I don't know where it is, hence why I'm asking if anyone is familiar with Smarty and may have seen such things before.

    I can find the actual code that is executing (it is the db_query() function in mysql.php) - it's finding the relevant code which is CALLING this function that is the tough bit. That SQL statement itself is defined in both the get_user_profile() and remove_user() functions in user_system.php, so my best guess would be that it is the get_user_profile() function that is being executed, but since the id value is being posted to the page, why the hell is this failing?

    Apart from that, THIS is the function that should be getting executed ...

    PHP Code:
    function chrole($id$role)
    $q "UPDATE users SET role=$role WHERE id = $id"; return db_query($qaffected_rows);

    ... per the flow of the admin code as evidenced below ...

    PHP Code:
            case 'chrole':
                {
                    if(isset(
    $role) && isset ($id)){
                        
    $user_data $g_user_system->chrole($id$role);
                    }else{
                        
    $user_data $g_user_system->get_user_profile($q_a[2]);
                        
    $echo.= "USER: ".$user_data['username'] ;
                        
    $echo .='<br /> ROLE ('.get_role_by_id($user_data['role']).'): <form action="'.site_main_url.'admin/chrole/" method="POST">
    <input type="hidden" name="id" value="'
    .$user_data['id'].'">
    <select name="role">
     <option value="2">'
    .get_role_by_id(2).'
     <option value="3">'
    .get_role_by_id(3).'
     <option value="4">'
    .get_role_by_id(4).'
     <option value="5">'
    .get_role_by_id(5).'
     <option value="10">'
    .get_role_by_id(10).'
    </select> <input type="submit">
    </form>'
    ;
                    }
                    break;
                } 
    ... since the if(isset($role) && isset ($id)) should be true. (First time into the page the form shows OK).

    HELP!
    Ian Anderson
    www.siteguru.co.uk

  10. #10
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You are actually looking for a select statemant.

    Anyway, still this has nothing to do with smarty.
    Still we don't see the whole action page. Somewhere on a page you should have something like:
    PHP Code:
    $id $_POST["id"];
    $role $_POST["role"]; 
    Do you have that?

    I don't see evidence of smarty anywhere in your posted code. You are using echo?
    -- Jelena --

  11. #11
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    It's not my site so I don't know what was used to create it. All I do know is that Smarty is part of the file system and is called within the templating.

    But ... you gave me a massive clue (of something that was smacking me in the face but I couldn't see it) regarding the $_POST. I changed the chrole part to this and all seems to work OK ...

    PHP Code:
            case 'chrole':
                {
                    
    $id = (int) $_POST['id'];
                    
    $role = (int) $_POST['role'];
    //                if(isset($role) && isset ($id)){
                    
    if ( !empty ($role) && !empty ($id) ) {
                        
    $user_data $g_user_system->chrole($id$role);
                        
    $echo .= $id ' user activated.<br /><a href="'.site_main_url.'admin/list/">Admin List</a>';
                    }else{
                        
    $user_data $g_user_system->get_user_profile($q_a[2]);
                        
    $echo.= "USER: ".$user_data['username'] ;
                        
    $echo .='<br /> ROLE ('.get_role_by_id($user_data['role']).'): <form action="'.site_main_url.'admin/chrole/" method="POST">
    <input type="hidden" name="id" value="'
    .$user_data['id'].'">
    <select name="role">
     <option value="2">'
    .get_role_by_id(2).'
     <option value="3">'
    .get_role_by_id(3).'
     <option value="4">'
    .get_role_by_id(4).'
     <option value="5">'
    .get_role_by_id(5).'
     <option value="10">'
    .get_role_by_id(10).'
    </select> <input type="submit">
    </form>'
    ;
                    }
                    break;
                } 
    Thanks for the help!
    Ian Anderson
    www.siteguru.co.uk

  12. #12
    SitePoint Wizard silver trophy Jelena's Avatar
    Join Date
    Feb 2005
    Location
    Universum, 3rd Corner
    Posts
    3,000
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You are welcome
    -- Jelena --


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •