PHP header doesnt redirect instead stays on same page -


i have ecommerce page using stripe api. once payment successful want redirect checkoutproc.php after updating db. after clicking submit page remain on same page. when try on local host works fine doesnt work when live. header @ bottom of checkout.php file given here-

<html> <head>   <title>unsq</title>   <link rel="stylesheet" type="text/css" href="css/styling.css">   <script type="text/javascript" src="https://js.stripe.com/v2/"></script>   <script src="http://code.jquery.com/jquery-1.11.1.js"></script> </head> <body>    <div class="logo" >     <img src=css/images/unsquaringlogo.png height="180" width="700">   </div>    <div class="container">     <h2>register</h2>      <form  action="" method="post" id="payment-form">        <span class="payment-errors"></span>          <div class="form-row">           <label>             <span>card number</span>             <input type="text" size="20" data-stripe="number"/>           </label>         </div>          <div class="form-row">           <label>             <span>cvc</span>             <input type="text" size="4" data-stripe="cvc"/>           </label>         </div>          <div class="form-row">           <label>             <span>expiration (mm/yyyy)</span>             <input type="text" size="2" data-stripe="exp-month"/>           </label>           <span> / </span>           <input type="text" size="4" data-stripe="exp-year"/>         </div>          <button type="submit" >submit payment</button>       </form>    </div>   <script type="text/javascript">   // identifies website in createtoken call below   stripe.setpublishablekey('mykey');   // ...   jquery(function($) {     $('#payment-form').submit(function(event) {       console.log("this 1");       var $form = $(this);       console.log($form);       // disable submit button prevent repeated clicks       $form.find('button').prop('disabled', true);       console.log("this 2");       stripe.card.createtoken($form, striperesponsehandler);       console.log("this 3");       // prevent form submitting default action       return false;     });   }); </script>  <script>      function striperesponsehandler(status, response) {        console.log("this 5");       var $form = $('#payment-form');        if (response.error) {         // show errors on form         $form.find('.payment-errors').text(response.error.message);         $form.find('button').prop('disabled', false);       } else {         // response contains id , card, contains additional card details         $form.find('.payment-errors').text("success");         var token = response.id;         // insert token form gets submitted server         $form.append($('<input type="hidden" name="stripetoken" />').val(token));         // , submit         $form.get(0).submit();         }     };  </script>  <?php  if ($_server['request_method'] == 'post') {      $errors = array();     if (isset($_post['stripetoken'])) {        $token = $_post['stripetoken'];        require_once('stripe-php/init.php');       \stripe\stripe::setapikey("mykey");        // credit card details submitted form       $token = $_post['stripetoken'];        // create charge on stripe's servers - charge user's card       try {         $charge = \stripe\charge::create(array(           "amount" => 1000, // amount in cents, again           "currency" => "usd",           "source" => $token,           "description" => "payinguser@example.com")         );          include('config.php');         $sql="insert login (email,name,password)values('$_get[email]','$_get[username]','$_get[password]')";         $result=mysqli_query($conn,$sql) or die(mysqli_error());  // ***************this header redirect*******             header('location:checkoutproc.php');        } catch(\stripe\error\card $e) {           // card has been declined       }     } } else {   $errors['token'] = 'the order cannot processed. have not been charged. please confirm have javascript enabled , try again.'; }  ?> </body>   </html> 

this how *checkoutproc.php* looks

<?php             print "<h1>you have registered sucessfully</h1>";             print "<a href='index.php'>go login page</a>"; ?> 

this how config.php looks like

<?php $servername = "localhost"; $username = "*****"; $password = ****; $dbname='unsq';    // create connection $conn = new mysqli($servername, $username, $password,$dbname);  // check connection if ($conn->connect_error) {     die("connection failed: " . $conn->connect_error); }  echo "connected !!"; ?> 


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -