0

So Im developing Content Management System for my website! (Very Basic and I know some of these codes are going to be bad).

So Im using PDO and when I run this code.

public static function checkMain()
    {
        global $dbh;
        if (isset($_POST['checkMain']))
        {

     $checkMain = $dbh->prepare("UPDATE `cms_system` SET `site_closed` = :site_closed LIMIT 1");
     $checkMain->bindParam(':site_closed', $_POST['site_closed']);
     if (!$checkMain->execute()) 
     {
        {
            admin::succeed("no error");
            return true;
        }
        admin::error("Uh Oh something is wrong" . $checkMain->errorInfo()[2]);
    return;
        }
    }
  }

Nothing happens I get no result nor does anything get updated in the database.

Here is my form tags

    <form action="" method='POST' name='theAdminForm' id='theAdminForm'>
<div class='tableborder'>
<div class='tableheaderalt'>Turn your site on/off</div>
<?php admin::checkMain(); ?>
<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='checkMain'  class='dropdown'>
                                    <option value='0'>Site Open</option>
                                    <option value='1'>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>

Pretty much in a nutshell Im converting this really old Query

if(isset($_POST['site_closed'])){

$site_closed = addslashes($_POST['site_closed']);

mysql_query("UPDATE cms_system SET site_closed = '".$site_closed."' LIMIT 1") or die(mysql_error());
$msg = "Settings saved successfully.";

The Old Forum Tags.

    <form action='index.php?p=maintenance&do=save' method='post' name='theAdminForm' id='theAdminForm'>
<div class='tableborder'>
<div class='tableheaderalt'>Turn your site on/off</div>

<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='site_closed'  class='dropdown'>
                                    <option value='1'>Site Closed</option>
                                    <option value='0' <?php if(FetchCMSSetting('site_closed') == "0"){ echo "selected='selected'"; } ?>>Site Open</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>

Into little but more updated version using PDO.

  • Try debugging content of variables. If nothing changes in database, 1. do you have connection? try `var_dump($dbh);` - ifnnot, here's the problem, 2. is this expression true `isset($_POST['checkMain'])`? try `var_dump($_POST['checkMain'])` - if is empty or false or null - here's the problem – Daniel Vítek Apr 17 '20 at 22:11
  • There is no `name="site_closed"` in the new form. – Barmar Apr 17 '20 at 22:24
  • `$_POST['site_closed']` should be `$_POST['checkMain']` – Barmar Apr 17 '20 at 22:25
  • @DanielVítek I did var_dump and its coming back NULL – Richard Begin Apr 17 '20 at 22:25
  • @Barmar Its in the select tag. and Because the function is ```checkMain``` the name tag is correct. – Richard Begin Apr 17 '20 at 22:29
  • You have ` – Barmar Apr 17 '20 at 22:31
  • Does this answer your question? [My PDO Statement doesn't work](https://stackoverflow.com/questions/32648371/my-pdo-statement-doesnt-work) – Dharman Apr 17 '20 at 23:28

0 Answers0