ПРОВЕРЬТЕ КОД В БД ПЕРЕД ПОДТВЕРЖДЕНИЕМ СДЕЛКИ С ПОМОЩЬЮ SWEETALERT 2 - PullRequest
0 голосов
/ 17 июня 2020

Я хочу сравнить входной код в sweetalert со всеми значениями поля кода в моей табличной транзакции, если код существует, и мы можем подтвердить транзакцию, иначе вставьте валидный код. Проблема в том, что сравнение производится только с последним значением поля кода таблицы транзакций, а не со всеми значениями поля кода. Это мой сценарий:

<script>
    $(document).ready(function(){

        readProducts(); /* it will load products when document loads */

        $(document).on('click', '#update_product', function(e){

            var productId = $(this).data('id');
            SwalDelete(productId);
            e.preventDefault();
        });

    });

function SwalDelete(productId){

       ///your customer key value.
swal({
    title: 'Submit secret key to confirm ',
    input: 'text',
    inputPlaceholder:"Enter your secret key",
    showCancelButton: true,
    confirmButtonColor: "#1FAB45",
    confirmButtonText: "Confirm",
    cancelButtonText: "Cancel",
    buttonsStyling: true,
    showLoaderOnConfirm: true,

preConfirm: function(text) {
              return new Promise(function(resolve, reject) {
                setTimeout(function(){

                    if (text != <?php var_export($result) ;   ?>){
                        reject('This secret is not valid.')

                    } else{


                    $.ajax({
                    url: 'components/delete.php',
                    type: 'POST',
                    data: 'update='+productId,
                    dataType: 'json'
                 })
                 .done(function(response){
                    swal('Deleted!', response.message, response.status);
                    readProducts();
                 })
                 .fail(function(){
                    swal('Oops...', 'Something went wrong with ajax !', 'error');
                 });

                 reslove()

                    }
                }, 1000)
                })
                },
                allowOutsideClick: false
                }).then(function (text) {
                    swal({
                        type: 'success',
                        title: 'Ajax request finished!',
                        html: 'Submitted key:' + text
                    })
                } )

    }

    function readProducts(){
        $('#load-products').load('components/notify.php');
    }

</script>

$query = 'SELECT * FROM transaction ';
$stmt = $DBcon->prepare( $query );
$stmt->execute(); 
if($stmt->rowCount() > 0) {
    while($row=$stmt->fetchAll(PDO::FETCH_ASSOC)) 
          {
      foreach($row as $result){
       $code=$result['merchant_code'];
          var_export($code);
            }

       }
...