Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Maintenance System

Custom Title Activated
Member
Joined
Jun 27, 2009
Messages
1,571
Reaction score
170
Hello!

I need assistance with Maintenance System for BrainCMS.

Here is my checkMaintenance function.

PHP:
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:
<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:
CREATE TABLE `cms_system` (
  `systemVar` varchar(50) NOT NULL,
  `value` text 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');
 
Junior Spellweaver
Joined
Jul 28, 2019
Messages
162
Reaction score
308
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:
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:
Upvote 0
Custom Title Activated
Member
Joined
Jun 27, 2009
Messages
1,571
Reaction score
170
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:
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:
Fatal error: Uncaught Error: Cannot 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.
 
Upvote 0
Joined
Feb 7, 2010
Messages
1,850
Reaction score
1,004
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)?
 
Upvote 0
Custom Title Activated
Member
Joined
Jun 27, 2009
Messages
1,571
Reaction score
170
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.

Glee - Maintenance System - RaGEZONE Forums


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.
 
Upvote 0
Custom Title Activated
Member
Joined
Jun 27, 2009
Messages
1,571
Reaction score
170
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:
Fatal error: Uncaught Error: Cannot 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:
$checkMaintenance->bindParam(':siteOption', $siteOption?'open':'closed');
 
Upvote 0
Joined
Feb 7, 2010
Messages
1,850
Reaction score
1,004
So Im getting this error.

PHP:
Fatal error: Uncaught Error: Cannot 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:
$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.
 
Upvote 0
Custom Title Activated
Member
Joined
Jun 27, 2009
Messages
1,571
Reaction score
170
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:
Upvote 0
Joined
Feb 7, 2010
Messages
1,850
Reaction score
1,004
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
 
Upvote 0
Custom Title Activated
Member
Joined
Jun 27, 2009
Messages
1,571
Reaction score
170
I give full credit to Joorren for this.

PHP:
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");
    		}
        }
    
    }
 
Upvote 0
Experienced Elementalist
Joined
Oct 5, 2010
Messages
260
Reaction score
109
I give full credit to Joorren for this.

PHP:
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");
    		}
        }
    
    }

Is it working?
 
Upvote 0
Back
Top