@OnCode

Ошибка Undefined index ../ php?

При нажатии на кнопку по появлется окно. (Плагин Sweetalert2)
5ee62605bcacc904091672.jpeg
из первого input данные в strAns1 а из второго strAns2.

Ошибка Undefined index: strAns1 / strAns2 in price_contact_us.php on line 4 / 5
Проблема в $name = $_POST['strAns1']; они не определяются в php.

Спасибо за помощь.
--------------------------------
$(document).ready(function() {
    $('input.ppa').on("click", function() {

  var strAns1;
    var strAns2;

    swal.mixin({

      input: 'text',
      confirmButtonText: 'Next →',
      showCancelButton: true,
      progressSteps: ['1', '2', '3']

    }).queue([
      {
        title: 'Question 1',
        text: 'Chaining swal2 modals is easy',
        preConfirm: function(value)
                {
                    strAns1= value;
                }
      },

      {
        title: 'Question 2',
        text: 'Chaining swal2 modals is easy',
        preConfirm: function(value)
                {
                    strAns2= value;
                }
      }
    ]).then((result) => {
      if (result.value) {
        Swal.fire({
          title: 'All done!',
          html:
            'Your answers: <pre>' +
              JSON.stringify(result) +
            '<pre>Answer1- ' + strAns1+
            '<pre>Answer2- ' + strAns2+
            '</pre>',
          confirmButtonText: 'Lovely!'
        })

        $.ajax({
        method: "POST",
        url: "pages/price_contact_us.php",
        data: { Name: strAns1, Number: strAns2, },
        success: function(data){
         console.log(data);
     }
        })
          .done(function(msg) {
          });
      }
    })
  })});


---------------------
<?php
 include '../config/connect.php';

$name = $_POST['strAns1'];
$number = $_POST['strAns2'];

if ($mysql->connect_error) {
  die("Connection failed: " . $mysql->connect_error);
}

$sql = ("INSERT INTO `contact_us` (`Name`, `Number`) VALUES ('$name', '$number')");
  • Вопрос задан
  • 112 просмотров
Решения вопроса 1
nokimaro
@nokimaro
Меня невозможно остановить, если я смогу начать.
$name = $_POST['Name'];
$number = $_POST['Number'];
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы