E
E
eSCphr2018-01-27 15:51:54
PHP
eSCphr, 2018-01-27 15:51:54

The tariff plan is not added to the database, what's the problem?

Where is the error in the code, I can’t understand
. It writes what was added, but there is nothing in the database ..

<?php
          if (isset($_POST['addPackage']))
          {
            $name = $_POST['name'];
            $price = $_POST['price'];
            $length = $_POST['length'];
            $unit = $_POST['unit'];
            $maxboot = $_POST['maxboot'];
            $concurrents = $_POST['concurrents'];
            $methods = $_POST['methods'];
            $public = $_POST['public'];
            $errors = array();
            
              if (empty($name) || empty($price) || empty($length) || empty($unit) || empty($maxboot) || empty($concurrents) || empty($methods) || empty($public))
              {
                $errors[] = 'Please fill in all fields.';
              }
              
              if(empty($errors)) {
                $insertPackage = $odb -> prepare("INSERT INTO `packages` VALUES (NULL, :name, :price, :maxboot, :unit, :length, :concurrents, :methods, :public, :hoston)");
                $insertPackage -> execute(array(':name' => $name, ':price' => $price, ':maxboot' => $maxboot, ':unit' => $unit, ':length' => $length, ':concurrents' => $concurrents, ':methods' => json_encode($methods), ':public' => $public, ':hoston' => $hoston));
                echo '<div class="alert alert-success"><a class="close" data-dismiss="alert" href="#" aria-hidden="true">×</a><strong>Success!</strong><br> You have added a new package successfully!</div>';
              } else {
                echo '<div class="alert alert-danger"><a class="close" data-dismiss="alert" href="#" aria-hidden="true">×</a><strong>Error!</strong><br />';
                foreach($errors as $error)
                {
                  echo '- '.$error.'<br />';
                }
                echo '</div>';
              }
          }
        ?>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question