E
E
eSCphr2018-01-28 14:03:58
PHP
eSCphr, 2018-01-28 14:03:58

Doesn't query which package, what's the problem?

Hello, I can't figure out where I'm wrong... The code is created but doesn't get the package id from the "packages" table

<?php
        if(isset($_POST['createnewCard']))
    {
    $plan = $_POST['plan'];
    $errors = array();

        if(empty($plan))
    {

         $errors[] = 'Такого тарифного плана не существует!';

        }
    if(empty($errors))
    {
       /// Генератор кода
      $code = substr(base_convert(sha1(uniqid(mt_rand())), 16, 36), 0, 10);
      
       /// Вход в базу данных
      $SQLinsert = $odb -> prepare("INSERT INTO `giftcards` VALUES(NULL, :code, :planID, 0, 0, UNIX_TIMESTAMP())");
      $SQLinsert -> execute(array(':code' => $code, ':planID' => $plan));	
            echo $design->alert('success', 'Success', 'Создана новая подарочная карта. Code: '.$code.'');
      } else {

                                                    echo '<div class="alert alert-danger alert-dismissable">Ошибка!</br>';

                                                    foreach($errors as $error){

                                                        echo ' - '.$error.'';

                                                    }

                                                    echo ' </div>';
    }	
  }
  ?>

<select class="form-control" name="plan[]">
                  <?php
                  $GetPackages = $odb -> query("SELECT * FROM `packages`");
                                    while($getInfo = $GetPackages -> fetch(PDO::FETCH_ASSOC))
                  {
                  $ID = $getInfo['ID'];
                  $name = $getInfo['name'];
                  echo '<option value="'.$ID.'">'.$name.'</option>';
                  }
                  ?>
                </select>

Where is the error in the code?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
OKyJIucT, 2018-01-28
@eSCphr

You have an array in $_POST['plan'] and you insert it as a number.
Instead of name="plan[]" in the form, write name="plan"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question