Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8254059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:04:49+00:00 2026-06-08T01:04:49+00:00

I’m trying to create a loop, which redirects to another script when the condition

  • 0

I’m trying to create a loop, which redirects to another script when the condition is met. But at the moment, it meets the condition, ends the loop, but doesn’t redirect to the script. Nothing I have done works…

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
define('INCLUDE_CHECK',true);
require '../config/connection.php';
session_name('ppRemember');
session_set_cookie_params(86400);
session_start();
//get value from database. if is pending then display loading else display summary. if is complete but no session set say session has expired
if (isset($_SESSION['txnId'])) {
if ($_SESSION['txnId']==true) {
    header('Location: ../confirmation');
    die();
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body> 
<div id="basket-empty" title="Success" style="display:none;">
<p>Basket emptied</p>
</div>
<div id="confirm-empty" title="Confirm" style="display:none;">
<p>Are you sure you want to empty your basket?</p>
</div>
<div id="page-wrapper">
    <div id="page">
        <div id="header" class="without-secondary-menu">
                <div class="section clearfix">
                    <div id="logo-caption">
                        <a href="/" title="Home" rel="home" id="logo">
                        </a>
                    </div>
                    <div id="caption">
                    </div>
                    <div id="main-menu" class="navigation">
                        <ul id="main-menu-links" class="links clearfix">
                            <li class="menu-2 active-trail active"><a href="../index"> Order Online </a></li>
                            <li class="menu-9"><a href="../my-account"> My Account </a></li>
                            <?php if (!$_SESSION['id']) {?>
                            <li class="menu-10"><a href="../login"> Sign In </a></li>
                            <?php } ?>
                            <li class="menu-5"><a href="../getaquote"> Get a Quote </a></li>
                            <li class="menu-6"><a href="../contactus"> Contact Us </a></li>
                            <li class="menu-11"><a href="../news"> News </a></li>
                            <li class="menu-8"><a href="../uploads"> Uploads </a></li>
                            <li class="menu-7"><a href="../downloads"> Downloads </a></li>
                        </ul>           
                    </div>
                </div>
            </div>
            <?php if (isset($_SESSION['id'])) { ?>
                <div id="panel" class="clearfix">
                    <div id="account-links">
                        <ul class="username">
                            <li><span class="account-links"><a href="../my-account">You are logged in as <b><?php echo $_SESSION['username']; ?></b></a></span>
                            <span class="logout"><a href="../destroy">Logout</a></span></li>
                        </ul>   
                    </div>
                </div>
            <?php } ?>  
        <div id="main-wrapper" class="clearfix">
            <div id="main" class="clearfix">
                <div class="content">
                    <a id="main-content"></a>
                    <div class="tabs">
                    </div>
                    <div class="region region-content">
                        <div id="block-system-main" class="block block-system">
                            <div class="content">
                                <div id="node-1" class="clearfix">
                                    <div class="content clearfix">
                                        <?php if (!isset($_SESSION['txnId'])) {
                                        if (isset($_SESSION['cart'])) { ?>
                                        <div class="loading2" style="height:300px;">
                                            <span class="text2"><font size="6pt"><b>Loading....</b></font></span>
                                            <img src="../images/ajax-loader2.gif"/><br />
                                            <font size="3pt"><b>Please wait a moment whilst we process your payment</b></font><br />
                                            <font size="1pt"><b>Click <a href="/order/complete">here</a> to reload after 10 seconds</b></font>
                                        </div>
                                        <?php }
                                        } ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div id="footer-wrapper">
                <div class="section">
                    <div id="footer" class="clearfix">
                        <div class="region region-footer">
                            <div class="block">
                                <div class="content">
                                    <div class="column1">
                                    </div>
                                    <div class="column2">
                                                                                </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html> 
<?php
$trans = $_SESSION['transaction_id'];
$clientId = $_SESSION['id'];
if (!isset($_SESSION['txnId'])){
    while ($_SESSION['txnId']!=true) {
        $mysqli = new mysqli("localhost", "#####", "#####", "######");
        $stmt = $mysqli->prepare("SELECT `txn_id` FROM `trans` AS t, `order_table` AS ot, `customer_order_details` AS cod WHERE t.transaction_id=?
         && t.transaction_id = ot.transaction_id && ot.customer_order_details_id = cod.customer_order_details_id && cod.client_id=?");
        $stmt->bind_param('ii',$trans,$clientId);
        if ($stmt->execute()) {
            $stmt->store_result(); 
            $num_rows = $stmt->num_rows;
            if ($num_rows>=1) {
                $stmt->bind_result($txnidrow);
                $stmt->fetch();
                $stmt->free_result();
                $stmt->close();
                $_SESSION['CARRYTXNID'] = $txnidrow;    
                $_SESSION['txnId'] = true;
            }
        }
    } 
}
header('Location: ../confirmation');
die();
}

?>

Any headway is greatly appreciated. I’ve tried a do while loop, header without die/exit. I’ve removed all code and redirected the page on it’s own, ran the script and all is fine. Etc, etc. I echo’d something to make sure that the condition is finally met, as well.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T01:04:51+00:00Added an answer on June 8, 2026 at 1:04 am

    Following your edit, the solution here is actually quite simple – all you need to do is move the redirect code to the top of the page:

    <?php
    
      define('INCLUDE_CHECK',true);
      require '../config/connection.php';
    
      session_name('ppRemember');
      session_set_cookie_params(86400);
      session_start();
    
      $trans = $_SESSION['transaction_id'];
      $clientId = $_SESSION['id'];
    
      //get value from database. if is pending then display loading else display summary. if is complete but no session set say session has expired
      if (isset($_SESSION['txnId'])) {
        if ($_SESSION['txnId']==true) {
          header('Location: ../confirmation');
          die();
        }
      } else {
        while (!$_SESSION['txnId']) {
          $mysqli = new mysqli("localhost", "#####", "#####", "######");
          $stmt = $mysqli->prepare("
            SELECT `txn_id`
            FROM `trans` AS t, `order_table` AS ot, `customer_order_details` AS cod
            WHERE t.transaction_id = ?
               && t.transaction_id = ot.transaction_id
               && ot.customer_order_details_id = cod.customer_order_details_id
               && cod.client_id = ?
          ");
          $stmt->bind_param('ii', $trans, $clientId);
          if ($stmt->execute()) {
            $stmt->store_result(); 
            $num_rows = $stmt->num_rows;
            if ($num_rows>=1) {
              $stmt->bind_result($txnidrow);
              $stmt->fetch();
              $stmt->free_result();
              $stmt->close();
              $_SESSION['CARRYTXNID'] = $txnidrow;    
              $_SESSION['txnId'] = true;
            }
          }
        } 
      }
      header('Location: ../confirmation');
      die();
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    </head>
    <body> 
    <div id="basket-empty" title="Success" style="display:none;">
    <p>Basket emptied</p>
    </div>
    <div id="confirm-empty" title="Confirm" style="display:none;">
    <p>Are you sure you want to empty your basket?</p>
    </div>
    <div id="page-wrapper">
        <div id="page">
            <div id="header" class="without-secondary-menu">
                    <div class="section clearfix">
                        <div id="logo-caption">
                            <a href="/" title="Home" rel="home" id="logo">
                            </a>
                        </div>
                        <div id="caption">
                        </div>
                        <div id="main-menu" class="navigation">
                            <ul id="main-menu-links" class="links clearfix">
                                <li class="menu-2 active-trail active"><a href="../index"> Order Online </a></li>
                                <li class="menu-9"><a href="../my-account"> My Account </a></li>
                                <?php if (!$_SESSION['id']) {?>
                                <li class="menu-10"><a href="../login"> Sign In </a></li>
                                <?php } ?>
                                <li class="menu-5"><a href="../getaquote"> Get a Quote </a></li>
                                <li class="menu-6"><a href="../contactus"> Contact Us </a></li>
                                <li class="menu-11"><a href="../news"> News </a></li>
                                <li class="menu-8"><a href="../uploads"> Uploads </a></li>
                                <li class="menu-7"><a href="../downloads"> Downloads </a></li>
                            </ul>           
                        </div>
                    </div>
                </div>
                <?php if (isset($_SESSION['id'])) { ?>
                    <div id="panel" class="clearfix">
                        <div id="account-links">
                            <ul class="username">
                                <li><span class="account-links"><a href="../my-account">You are logged in as <b><?php echo $_SESSION['username']; ?></b></a></span>
                                <span class="logout"><a href="../destroy">Logout</a></span></li>
                            </ul>   
                        </div>
                    </div>
                <?php } ?>  
            <div id="main-wrapper" class="clearfix">
                <div id="main" class="clearfix">
                    <div class="content">
                        <a id="main-content"></a>
                        <div class="tabs">
                        </div>
                        <div class="region region-content">
                            <div id="block-system-main" class="block block-system">
                                <div class="content">
                                    <div id="node-1" class="clearfix">
                                        <div class="content clearfix">
                                            <?php if (!isset($_SESSION['txnId'])) {
                                            if (isset($_SESSION['cart'])) { ?>
                                            <div class="loading2" style="height:300px;">
                                                <span class="text2"><font size="6pt"><b>Loading....</b></font></span>
                                                <img src="../images/ajax-loader2.gif"/><br />
                                                <font size="3pt"><b>Please wait a moment whilst we process your payment</b></font><br />
                                                <font size="1pt"><b>Click <a href="/order/complete">here</a> to reload after 10 seconds</b></font>
                                            </div>
                                            <?php }
                                            } ?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div id="footer-wrapper">
                    <div class="section">
                        <div id="footer" class="clearfix">
                            <div class="region region-footer">
                                <div class="block">
                                    <div class="content">
                                        <div class="column1">
                                        </div>
                                        <div class="column2">
                                                                                    </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I'm trying to select an H1 element which is the second-child in its group
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.