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 9013321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:14:04+00:00 2026-06-16T03:14:04+00:00

I know the code is pretty long…but I hope the solution I’m looking for

  • 0

I know the code is pretty long…but I hope the solution I’m looking for is simple and quick. So I have a session working here on my order form. I have two forms echoed depending if the person is logged in. First if statement is if the user is logged in, it does all that stuff (I know the code is not perfect but it works for me). The question:
How can I redirect the user to their account after placing the order? I tried the header function before the }else{…didn’t work, took me right to the account page. I couldn’t find the code online because their forms were all inside html, not inside php, so the header didn’t work. Any advice???

<?php

    $memberOrder = "";
    $nonmemberOrder = "";

if(isset($_SESSION['id'])){

    include_once "connect_to_mysql.php";

    echo '<script type="text/javascript">

    function validate_form ( ) { 
    var numbers = /^[0-9]+$/;
    valid = true;

    if ( document.memberOrder.memberNumber.value == "" ) { 
    alert ( "Membership number must be entered." ); 
    valid = false;
    }
    if ( document.memberOrder.memberNumber.value.match(numbers)){
        valid = true;
    }else{
        alert ( "You must only have numbers entered as Membership Number.");
        valid = false;
    }
    if ( document.memberOrder.payment.value == "" ) { 
    alert ( "You must select a payment method." ); 
    valid = false;
    }
    if ( document.memberOrder.orderLinks.value == "" ) { 
    alert ( "You must insert a link to your order." ); 
    valid = false;
    }
    if ( document.memberOrder.size.value == "" ) { 
    alert ( "Size must not be blank." ); 
    valid = false;
    }
    if ( document.memberOrder.cost.value == "" ) { 
    alert ( "Cost must not be blank." ); 
    valid = false;
    }
    if ( document.memberOrder.cost.value.match(numbers)){
        valid = true;
    }else{
        alert ( "You must only have numbers entered as your item cost.");
        valid = false;
    }
    if (!document.memberOrder.checkbox.checked){
        alert ( "You must agree to terms before placing your order.");
        valid = false;
    }
    return valid;
    }
    </script>';

    $memberNumber = preg_replace("[^0-9]", "", $_POST['memberNumber']);
    $memberNumber = stripslashes($_POST['memberNumber']);
    $size = preg_replace("[^a-zA-Z]", "", $_POST['size']);
    $cost = preg_replace("[^0-9]", "", $_POST['cost']);
    $cost = stripslashes($_POST['cost']);
    $cost = strip_tags($cost);
    $color = preg_replace("[^a-zA-Z]", "", $_POST['color']);
    $color = stripslashes($_POST['color']);
    $color = strip_tags($color);
    $payment = $_POST['payment'];
    $orderLinks = $_POST['orderLinks'];

    $sql = mysql_query("INSERT INTO memberOrders (memberNumber, orderLinks, cost) VALUES 
                        ('$memberNumber', '$orderLinks', '$cost')") or die (mysql_error());

    $memberOrder = '<form action="order.php" method="post" name="memberOrder" id="memberOrder" onsubmit="return validate_form ( );">
                    <table cellpadding="10" width="500px">
                        <tr>
                            <td><div align="left">Membership Number</div></td>
                            <td><input type="text" name="memberNumber" id="memberNumber"  /></td>
                        </tr>
                        <tr>
                            <td><div align="left">Payment Type</div></td>
                            <td><input type="radio" name="payment" value="Bank Transfer" />Bank Transfer (recommended)<br/>
                                <input type="radio" name="payment" value="PayPal" />PayPal (additional 3% commission)<br/>
                                <input type="radio" name="payment" value="Western Union" />Western Union<br/>
                                <input type="radio" name="payment" value="MoneyGram" />MoneyGram<br/>
                            </td>
                        </tr>
                        <tr>
                            <td><div align="left">Link To Your Order</div></td>
                            <td><textarea rows="5" cols="20" name="orderLinks"  ></textarea></td>
                        </tr>
                        <tr>
                            <td><div align="left">Size</div></td>
                            <td><input style="width:50px" type="text" size="25px" name="size"  /></td>
                        </tr>
                        <tr>
                            <td><div align="left">Color</div></td>
                            <td><input type="text" size="25px" name="color"  /></td>
                        </tr>
                        <tr>
                            <td><div align="left">Cost of Your Item</div></td>
                            <td><input style="width:50px" type="text" name="cost"  /></td>
                        </tr>
                        <tr>
                            <td><div align="left">Order Agreement</div></td>
                            <td><input type="checkbox" name="checkbox" checked="checked" value="check" /><a href="#" id="agreement">View Order Agreement</a></td>
                        </tr>
                        <tr>
                            <td>&nbsp;</td>
                            <td><input type="submit" name="submit" value="Place Order!" /></td>
                        </tr>
                        </table>
</form>';
    echo $memberOrder;

    // Start assembly of Email Member the activation link
    $to = "yankeesmarket@gmail.com";
    // Change this to your site admin email
    $from = "$memberNumber";
    $subject = "Member Order Placed";
    //Begin HTML Email Message where you need to change the activation URL inside
    $message = '<html>
    <body bgcolor="#FFFFFF">
    Member Number:  '.$memberNumber.' <br/><br/>
    Payment Type:  '.$payment.' <br/><br/>
    Order Links:  '.$orderLinks.' <br/><br/>
    Size:  '.$size.' <br/><br/>
    Color: '.$color.' <br/><br/>
    Order Cost: '.$cost.' <br/><br/>
    </body>
    </html>';
    // end of message
    $headers = "From: $from\r\n";
    $headers .= "Content-type: text/html\r\n";
    $to = "$to";
    // Finally send the activation email to the member
    mail($to, $subject, $message, $headers);


}else{
  • 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-16T03:14:05+00:00Added an answer on June 16, 2026 at 3:14 am

    You cannot write anything to the browser and expect the header function to work. In order to set headers, the response body must be empty.

    So I suggest to do something like:

    if(isset($_POST['submit'])){
        // do the INSERT and whatnot
        // when finished call the header function
        header("Location: my_custom_page.php");
    }
    else{
        // output the form, javascript and what you need
    }
    

    So the first time the page loads, it will go in the else statement, because you have no POST data. This will print out the form and validation JavaScript. When the form gets submitted, the request lands in the if, and the order is placed, and then the client is redirected.

    Again, in the if statement, you are not allowed to make any echos. A very bad alternative to this, would be to echo a small javascript that does the redirect (I don’t recommend this. ever):

    <script>window.location.href = 'my_custom_page.php';</script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Its been a long time since I have programmed in C++, but I know
I know this code use to work, I must have accidentally changed something when
I know the code is missing (Someone will give negative numbers). But I only
I know inline code is preferable, but there's a bunch of code that's needed
This is a pretty newbie question- please know I'm aware of that. I have
I found myself keep writing pretty long one-liner code(influenced by shell pipe), like this:
The following code is pretty self-explanatory and my question is very simple : Why
I tried to convert some C code to Java, but it is working slightly
I have a pretty long running process which now freezes my application for a
I have pretty simple application with text entry and button. When user press on

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.