Maintenance System

Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Alpha Member Glee is offline
    Alpha MaleRank
    Jun 2009 Join Date
    Niagara Falls,Location
    2,224Posts

    Maintenance System

    Maintenance System
    Hello!

    I need assistance with Maintenance System for BrainCMS.

    Here is my checkMaintenance function.

    PHP Code:
    function checkMaintenance()
        {
            global 
    $config$dbh;
            if (isset(
    $_POST['checkMaintenance']))
            {
                switch (
    $_POST['siteOption']) {
                        case 
    1:
                        
    $siteMode "Site Open";
                        break;
                        case 
    2:
                        
    $siteMode "Site Closed";
                        break;
                    }
                    
    $checkMaintenance $dbh->prepare("INSERT INTO cms_system (site_closed) VALUES(:siteOption)");
                    
    $checkMaintenance->bindParam(':siteMode'$siteMode);
                    
    $checkMaintenance->execute();
                    
    Admin::succeed("Maintenance Mode Enabled");
                }
        
        } 
    Now when I attempt to use it on my site I do get the return for "Admin::succeed" but its not updating my selection in database.

    Here is my Code:

    PHP Code:
    <form action="" method='POST' name='theAdminForm' id='theAdminForm'>
    <div class='tableborder'>
    <div class='tableheaderalt'>Turn your site on/off</div>
    <?php admin::checkMaintenance(); ?>
    <table width='100%' cellspacing='0' cellpadding='5' align='center' border='0'>
    <tr>
    <td class='tablerow1'  width='40%'  valign='middle'><b>Close Site</b><div class='graytext'>If enabled, your site will be closed and show a maintenance page to regular users. Administrators can still login through Housekeeping.</div></td>
    <td class='tablerow2'  width='60%'  valign='middle'>
        <select name="checkMaintenance"  class='dropdown'>
                                        <option name="siteOption" value='1'>Site Open</option>
                                        <option name="siteOption" value='2'>Site Closed</option>            
        </select>
    </td>
    </tr>

    <tr>
    <tr><td align='center' class='tablesubheader' colspan='2' ><input type='submit' value='Apply' class='realbutton' accesskey='s'></td></tr>
    </form>
    The problem is it's not updating in the database.

    SQL:

    PHP Code:
    CREATE TABLE `cms_system` (
      `
    systemVarvarchar(50NOT NULL,
      `
    valuetext DEFAULT NULL
    ENGINE=InnoDB DEFAULT CHARSET=latin1;

    --
    -- 
    Dumping data for table `cms_system`
    --

    INSERT INTO `cms_system` (`systemVar`, `value`) VALUES
    ('ip''127.0.0.1'),
    (
    'language''en'),
    (
    'localhost''0'),
    (
    'reload_url''http://127.0.0.1/holov3/client.php'),
    (
    'site_closed''0'); 


  2. #2
    Super Moderator Biesmen is offline
    Super ModRank
    Apr 2007 Join Date
    2,434Posts

    Re: Maintenance System

    Your placeholder in the "INSERT INTO" query is ":siteOption" but you're binding a variable to a placeholder named ":siteMode"
    Forum Rules | Account Support | Subscribe
    RaGEZONE Facebook

    "The reason why people give up so fast is because they tend to look at how far they still have to go, instead of how far they have gotten."

  3. #3
    Alpha Member Glee is offline
    Alpha MaleRank
    Jun 2009 Join Date
    Niagara Falls,Location
    2,224Posts

    Re: Maintenance System

    Quote Originally Posted by Biesmen View Post
    Your placeholder in the "INSERT INTO" query is ":siteOption" but you're binding a variable to a placeholder named ":siteMode"
    I changed it but it's still not updating the database. When I place it into Maintenance Mode.

  4. #4
    Hardcore Member KittyChloe is offline
    MemberRank
    Jul 2019 Join Date
    147Posts

    Re: Maintenance System

    You're setting $siteMode to a string when it should be a true/false integer. 0 or 1, but since you're checking if the option is 1/2, I assume 1 = maintenance, 2 = normal.

    PHP Code:
    function checkMaintenance() {
        global 
    $config$dbh;

        if (isset(
    $_POST['checkMaintenance'])) {
            
    $siteOption $_POST['siteOption'];

            
    $checkMaintenance $dbh->prepare("INSERT INTO cms_system (site_closed) VALUES(:siteOption)");
            
    $checkMaintenance->bindParam(':siteOption', ($siteOption == 1)?(0):(1));
            
    $checkMaintenance->execute();

            
    Admin::succeed("Maintenance Mode Enabled");
        }

    Last edited by KittyChloe; 20-05-20 at 08:37 PM.
    [TABLE="width: 100%"][TR][TD]Project Cortex[/TD][TD][RIGHT]

    Please review the forum rules in regards to posting about Discord.

    - vLife

  5. #5
    Alpha Member Glee is offline
    Alpha MaleRank
    Jun 2009 Join Date
    Niagara Falls,Location
    2,224Posts

    Re: Maintenance System

    Quote Originally Posted by KittyChloe View Post
    You're setting $siteMode to a string when it should be a true/false integer. 0 or 1, but since you're checking if the option is 1/2, I assume 1 = maintenance, 2 = normal.

    PHP Code:
    function checkMaintenance() {
        global 
    $config$dbh;

        if (isset(
    $_POST['checkMaintenance'])) {
            
    $siteOption $_POST['siteOption'];

            
    $checkMaintenance $dbh->prepare("INSERT INTO cms_system (site_closed) VALUES(:siteOption)");
            
    $checkMaintenance->bindParam(':siteOption', ($siteOption == 1)?(0):(1));
            
    $checkMaintenance->execute();

            
    Admin::succeed("Maintenance Mode Enabled");
        }

    Ok that's weird. When I use this I get this error when I try to execute the code.

    PHP Code:
    Fatal errorUncaught ErrorCannot pass parameter 2 by reference in C:\xampp\htdocs\system\app\classes\class.admin.php:365 Stack trace#0 C:\xampp\htdocs\adminpan\sitesettings.php(24): Admin::checkMaintenance() #1 C:\xampp\htdocs\system\app\classes\class.html.php(227): include('C:\\xampp\\htdocs...') #2 C:\xampp\htdocs\adminpan\index.php(10): html::pageHK() #3 {main} thrown in C:\xampp\htdocs\system\app\classes\class.admin.php on line 365 
    I looked in the respected files. But I'm not seeing anything that could be causing the error.

  6. #6
    Joorren Joorren is offline
    Gold SubscriberRank
    May 2011 Join Date
    1,533Posts

    Re: Maintenance System

    Why are you inserting and not updating? I'm guessing there's already a table row with all the settings. You should be updating that row.

    Also how does the CMS check if the site is in maintenance? Is it a boolean check (true/false), an integer check (1/2/...) or a varchar check ('open'/'closed' or 'true'/'false' or something)?







  7. #7
    Alpha Member Glee is offline
    Alpha MaleRank
    Jun 2009 Join Date
    Niagara Falls,Location
    2,224Posts

    Re: Maintenance System

    Quote Originally Posted by Joorren View Post
    Why are you inserting and not updating? I'm guessing there's already a table row with all the settings. You should be updating that row.

    Also how does the CMS check if the site is in maintenance? Is it a boolean check (true/false), an integer check (1/2/...) or a varchar check ('open'/'closed' or 'true'/'false' or something)?
    Here is my sql structure.



    As far the of the CMS checking for Maintenance, from the database hasn't been coded. I only have the default maintenance from the brain-config.php.

    I almost forgot and yes Im using the UPDATE query I just forgot to modified it.

  8. #8
    Joorren Joorren is offline
    Gold SubscriberRank
    May 2011 Join Date
    1,533Posts

    Re: Maintenance System

    Try this code in the prepare statement:
    Code:
    UPDATE cms_system SET site_closed = :siteOption
    Also change your bindParam to:
    Code:
    ':siteOption', $siteOption?'open':'closed'







  9. #9
    Alpha Member Glee is offline
    Alpha MaleRank
    Jun 2009 Join Date
    Niagara Falls,Location
    2,224Posts

    Re: Maintenance System

    Quote Originally Posted by Joorren View Post
    Try this code in the prepare statement:
    Code:
    UPDATE cms_system SET site_closed = :siteOption
    Also change your bindParam to:
    Code:
    ':siteOption', $siteOption?'open':'closed'
    So Im getting this error.

    PHP Code:
    Fatal errorUncaught ErrorCannot pass parameter 2 by reference in C:\xampp\htdocs\system\app\classes\class.admin.php:371 Stack trace#0 C:\xampp\htdocs\adminpan\sitesettings.php(24): Admin::checkMaintenance() #1 C:\xampp\htdocs\system\app\classes\class.html.php(227): include('C:\\xampp\\htdocs...') #2 C:\xampp\htdocs\adminpan\index.php(10): html::pageHK() #3 {main} thrown in C:\xampp\htdocs\system\app\classes\class.admin.php on line 371 
    On line 371 is this code

    PHP Code:
    $checkMaintenance->bindParam(':siteOption'$siteOption?'open':'closed'); 

  10. #10
    Joorren Joorren is offline
    Gold SubscriberRank
    May 2011 Join Date
    1,533Posts

    Re: Maintenance System

    Quote Originally Posted by Glee View Post
    So Im getting this error.

    PHP Code:
    Fatal errorUncaught ErrorCannot pass parameter 2 by reference in C:\xampp\htdocs\system\app\classes\class.admin.php:371 Stack trace#0 C:\xampp\htdocs\adminpan\sitesettings.php(24): Admin::checkMaintenance() #1 C:\xampp\htdocs\system\app\classes\class.html.php(227): include('C:\\xampp\\htdocs...') #2 C:\xampp\htdocs\adminpan\index.php(10): html::pageHK() #3 {main} thrown in C:\xampp\htdocs\system\app\classes\class.admin.php on line 371 
    On line 371 is this code

    PHP Code:
    $checkMaintenance->bindParam(':siteOption'$siteOption?'open':'closed'); 
    Right,
    Either use bindValue instead of bindParam.
    Or keep using bindParam, but define the 2nd value ($siteOption?'open':'closed') as a parameter before binding it there.

    Unlike PDOStatement::bindValue(), the variable is bound as a reference and will only be evaluated at the time that PDOStatement::execute() is called.







  11. #11
    Alpha Member Glee is offline
    Alpha MaleRank
    Jun 2009 Join Date
    Niagara Falls,Location
    2,224Posts

    Re: Maintenance System

    Quote Originally Posted by Joorren View Post
    Right,
    Either use bindValue instead of bindParam.
    Or keep using bindParam, but define the 2nd value ($siteOption?'open':'closed') as a parameter before binding it there.
    Which one do you recommend? bindValue or bindParam?

    If I decide to keep bindParam, how would define the 2nd value before binding?

    Im learning all this of this for educational purpose, all assistance will be credited.

    UPDATE:

    I changed bindParam to bindValue. its still not updating the database.
    Last edited by Glee; 21-05-20 at 05:46 PM.

  12. #12
    Joorren Joorren is offline
    Gold SubscriberRank
    May 2011 Join Date
    1,533Posts

    Maintenance System

    Quote Originally Posted by Glee View Post
    Which one do you recommend? bindValue or bindParam?

    If I decide to keep bindParam, how would define the 2nd value before binding?

    Im learning all this of this for educational purpose, all assistance will be credited.

    UPDATE:

    I changed bindParam to bindValue. its still not updating the database.
    Add me on Discord, @Joorren#4443 so I can have a look over TeamViewer. It’ll safe a lot of guessing.
    I’ll post the solution in here afterwards for people with the same issue







  13. #13
    C# Developer neto737 is online now
    True MemberRank
    Oct 2010 Join Date
    Environment.csLocation
    274Posts

    Re: Maintenance System

    I'm just curious, why INSERT instead of UPDATE?

  14. #14
    Alpha Member Glee is offline
    Alpha MaleRank
    Jun 2009 Join Date
    Niagara Falls,Location
    2,224Posts

    Re: Maintenance System

    Quote Originally Posted by neto737 View Post
    I'm just curious, why INSERT instead of UPDATE?
    It’s an UPDATE I know that I just forgot to change the query.


    Sent from my iPhone using Tapatalk

  15. #15
    Alpha Member Glee is offline
    Alpha MaleRank
    Jun 2009 Join Date
    Niagara Falls,Location
    2,224Posts

    Re: Maintenance System

    I give full credit to @Joorren for this.

    PHP Code:
    function checkMaintenance()
        {
            global 
    $config$dbh;
            if (isset(
    $_POST['checkMaintenance']))
            {
                switch (
    $_POST['checkMaintenance']) {
                    case 
    'open':
                    default:
                        
    $siteMode "open";
                        break;
                    case 
    'closed':
                        
    $siteMode "closed";
                        break;
                }

                
    // Check if there's already a row
                
    $checkRow $dbh->prepare("SELECT * FROM cms_site");
                
    $checkRow->execute();

                
    // If the row already exists, update
                
    if ($checkRow->fetch()) {
                    
    $checkMaintenance $dbh->prepare("UPDATE cms_site SET site_closed = :siteOption");
                    
    $checkMaintenance->bindParam(':siteOption'$siteMode);
                    
    $checkMaintenance->execute();
                }
                
    // Else, insert
                
    else {
                    
    $checkMaintenance $dbh->prepare("INSERT INTO cms_site VALUES (:siteOption, '')");
                    
    $checkMaintenance->bindParam(':siteOption'$siteMode);
                    
    $checkMaintenance->execute();
                }

                if (
    $siteMode === 'open') {
                
    Admin::succeed("Maintenance Mode Disabled");
                }
                else {
                
    Admin::succeed("Maintenance Mode Enabled");
                }
            }
        
        } 



Page 1 of 2 12 LastLast

Advertisement