Cannot create filter record in DB - PHP

Viewed 30

I'm trying to create custom filters,. I have a "filters" table which is working with ID, name and allowed_category (which is an VARCHAR datatype) but the all that happens is it just refreshes the page, with no new record in the DB. CURRENT_URL is constant containing the URL of the current page..

The front-end page in filter-add.php:

<?php
$filter = new EditFilters();
?>

<form id="edit-form" action="<?php echo CURRENT_URL; ?>" method="post" enctype="multipart/form-data">
    <div class="nofield">
            <h3>Základní informace</h3>
            <div>
                <label>Název filtru* </label>
                <input id="makeurl" class="text" type="text" name="name" value="<?php echo $filter->row['name']; ?>"/>
            </div>

        <input type="submit" name="button" value="<?php echo $filter->button; ?>"/>
        <input type="checkbox" name="back" <?php if($filter->back==1) echo "checked=\"checked\""; ?> />A poté návrat na Přehled zobží
    </div>
</form>

The PHP class EditFilters where I have addFilter() function in filters.php:

class EditFilters {
    public $button;
    public $back;

    function __construct() {
        $this->button = "Přidat";
        $this->back = 0;
    }

    function addFilter(&$msg) {
      global $pdo;
      $add = true;

      if ($_POST['name']=="") {
        $add=false; 
        $msg->Error("add-false");
      }

      if($add) {
        $dotaz = $pdo->prepare("INSERT INTO filters (id, name, allowed_category) VALUES ('', '".$_POST['name']."', '7')");
        $dotaz->execute();
        $msg->Confirm("add-ok",1);

        if(isset($_POST['back'])) { 
            Header("Location: ".$_SESSION['back_adress']);
        } else { 
            Header("Location: ".CURRENT_URL);
        }
      }
    }
}

And I am executing it from index.php where I am using require_once 'filters.php' in this snippet:

    if(isset($_POST['filter']) || isset($_GET['filter'])) {
       if($_POST['filter']=="filter-add") EditFilters::addFilter($msg);  
    }

Can anybody tell me what I'm doing wrong or direct me?

0 Answers
Related