JezK
Edit File: changeNumber.php
<?php include('mainHeader.php'); $page=basename($_SERVER['PHP_SELF']); $countrycodes=$users->countries('dial_code',$recentPractCountry); $userID=$users->encrypt_decrypt('decrypt',$_REQUEST['uid']); // print_r($userID);exit; if($userID>0){ $userdet = $users->getusers('id',$userID); if(count($userdet)<=0){ echo "<script>alert('Invalid user details1');window.location='verifyMobile.php?uid=".$_REQUEST['uid']."';</script>"; } }else{ echo "<script>alert('Invalid user details2');window.location='verifyMobile.php?uid=".$_REQUEST['uid']."';</script>"; } if(isset($_POST['action']) && $_POST['action']=='changePhoneNumber'){ $errors=''; $existmobile=$users->getUsers('mobile',$_POST['changephone'],$userID); if(count($existmobile)>0){ $errors.="Given phone number already exist please enter new one\\n"; } if($errors==''){ $otpsent=$users->sendOtp($_POST['country_code'],$_POST['changephone'],$userID); // echo $otpsent;exit; if($otpsent>0){ echo "<script language='javascript'>alert('Successfully changed phone number please verify OTP');window.location='verifyMobile.php?uid=".$_REQUEST['uid']."'</script>"; }else{ echo "<script language='javascript'>alert('Phone number updation is failed');</script>"; } }else{ echo "<script language='javascript'>alert('".$errors."');</script>"; } } ?> <style> .change-num { float: left; position: absolute; top: 82px; padding: 7px 24px 7px 4px; left: 15px; } </style> <section class="mt-5 pt-4 loginUser-margin"> <div class="container-fluid bg-white text-dark border"> <div class="row p-4"> <div class="col-sm-8 col-md-5 col-lg-4 col-xl-3 side-border"> <img src="img/illustration1.png" width="250px" height="250px"> </div> <div class="col-sm-8 col-md-7 col-lg-8 col-xl-9"> <div class="row "> <div class="col-sm-8 col-md-8 col-lg-6 col-xl-6"> <form method="post" action="" autocomplete="off" onsubmit="return checkvalidation();"> <h6 class=" mb-5 style-login d-flex">Change Mobile <a href="verifyMobile.php?uid=<?php echo $_REQUEST['uid'];?>" class="text-primary justify-content-end d-flex fs-13">Back</a></h6> <div class="form-group mb-5"> <label for="mobile" class="fieldName">Mobile Number</label> <select name="country_code" id="country_code" class="change-num filterby"> <?php foreach($countrycodes as $k=>$v){ $selectedval=''; if(isset($_POST['country_code']) && $_POST['country_code']!='' && $_POST['country_code']==str_replace('+','', $v['dial_code'])) { $selectedval="selected"; } echo "<option value='".str_replace('+','', $v['dial_code'])."' ".$selectedval.">".$v['dial_code']."</option>"; } ?> </select> <input type="tel" class="form-control formField-control w-100 mobilenoLeftalign" name="changephone" id="mobile" maxlength="15" autocomplete="off" autofocus value="<?php echo isset($_POST['mobile'])?$_POST['mobile']:'';?>"/> </div> <div class="form-group "> <input type="hidden" name="action" value="changePhoneNumber"> <input type="hidden" name="uid" value="<?php echo $_REQUEST['uid'];?>"> <!-- <input type="hidden" name="action" value="otpverification"> <input type="hidden" name="uid" id="uid" value="<?php echo $id;?>"> <input type="hidden" name="mobilenum" id="mobilenum" value="<?php echo $userdet['0']['mobile'];?>"> --> <button class="btn basic-btn-color w-100" >Change Number</button> </div> </form> </div> </div> </div> </div> </div> </section> <?php include('mainFooter.php')?> <script type="text/javascript"> function checkvalidation() { var phoneno = /^\d{5,15}$/; if($('#mobile').val()=='') { alert("Please enter mobile number");return false; } else if(!$('#mobile').val().match(phoneno)) { alert("Please enter valid Mobile Number");return false; } } function resendOtp(uid){ var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { if(this.responseText == 1){ alert("Successfully sent otp to your mobile number"); return false; }else if(this.responseText==0){ alert("OTP sending failed"); return false; } } }; xmlhttp.open("POST", "ajax.php?mid=" + uid +"&action=resendotp", true); xmlhttp.send(); } </script>