开发者

OTP Verify ajax response giving error with if condition

开发者 https://www.devze.com 2022-12-07 19:53 出处:网络
I am trying to make multi step form using ajax everithing is working fine but when I enter wrong otp to verify then obviously it will show Invalid otp and after then when I enter correct otp whithout

I am trying to make multi step form using ajax everithing is working fine but when I enter wrong otp to verify then obviously it will show Invalid otp and after then when I enter correct otp whithout refreshing page otp is verified successfully but next step form is not showing. In php code is like this if (isset($POST['VBPNOTP'])) {then insert data in data base code will be here}else{echo 0;}

PHP CODE

    if (isset($POST['VBPNOTP'])) {
                  $OTP=$POST['OTP'];
                  $data['email'] = $_SESSION['email'];
                  $sql = "select * from user where email = :email limit 1";
                  $che开发者_JS百科cking = $db->read($sql,$data);
                  $data['otp'] = $checking[0]->otp;
    
                  if ($data['selotp'] == $OTP) {
                    $data['sel']= 0;
                    $data['email'] = $_SESSION['email'];
                    $query = ("UPDATE user SET otp = :otp WHERE email = :email");
                    $result2 = $db->write($query,$data);
          
                    if($result2) {
                      echo 1; 
                    }else{
                      echo 0;
                    }
                  }else{
                    echo 0;
                  }
                }

AJAX CODE

$(document).on("click","#vfotp",function verify_code(e) {
              var OTP = $("#OTP").val();
              //var regexPhone = /^[6789][0-9]{9}$/;
                $.ajax({
                  url: "<?= BASEURL ?>ajax",
                  type: "POST",
                  datatype:"JSON",
                  data:{OTP:OTP},
                  success: function (data) {
                          console.log(data);
                          if(data==1){
                              console.log('good');
                              $("#smpv")[0].reset();
                              $('#phoneif').removeClass('active');
                              $('#storeif').addClass('active');
                              $('.step-progress-list-eiwgzy:nth-child(1)').removeClass('current-item');
                              $('.step-progress-list-eiwgzy:nth-child(2)').addClass('current-item');
                              //$("#smpv")[0].reset();
                            }else{
                              console.log('pumpoo')
                              $(".permsgOTP").html("OTP is Invalid");
                              $('#VBPNOTP').css({'border-color':'red'});

                            }

                  });
                  e.preventDefault();
    });
0

精彩评论

暂无评论...
验证码 换一张
取 消