I have been hesitant to post this bug because of the lengthy code and detailed explanation it would require. However, after many days of working on this problem without a solution I turn to you guys for help. Thanks in advance.

I have an HTML form called new_order.inc which POSTS to new_order.php. Here's the code for both pages, I have simplified the code for clarity. I'll explain the problem first and if you want to see the entire code afterwards, just let me know.

new_order.inc
------------------
PHP Code:
// beginning html here

// javascript
<script language="JavaScript1.2">
<!--
function isReady(form) {
     if (!isFilled(form.po_number)) {
          alert("Please enter the purchase order number.");
          form.po_number.focus();
          return false;
     }
    
     <?php
     
// print out only if is_scheduled is '1' or YES
     
if ($_SESSION["paper_proof"]["is_scheduled"] == "1") {
     
?>
    
     else if (!isDate(form.expected_date)) {
          alert("The paper proof expected date is in an incorrect format.");
          form.expected_date.focus();
          return false;
     }

     <?php ?>

     else {
          form.type.value = "add";
          
          // debugging JS 
          alert("before submit form");

          form.submit();

          // debugging JS again
          alert("after submit form");
     }
     return true;
}

function refreshFocusPage(form, element) {
     form.type.value = element;
     form.submit();
     return true;
}
//-->
</script>


// start form
<form name="new_order" method="post" action="<?php echo $SCRIPT_PATH;?>new_order.php">

// a mass of text and textarea fields
// including the po_number field

// paper proof radio button
<tr valign="top" class="text">
     <td>Is a paper proof scheduled?:</td>
     <td>&nbsp;</td>
     <td>Yes<input onClick="return refreshFocusPage(new_order, 'paper')" type="radio" name="pp_is_scheduled" value="1" <?php if($_SESSION["paper_proof"]["is_scheduled"] == "1") { echo " checked"; }?>>
            &nbsp;No<input onClick="return refreshFocusPage(new_order,  'paper')" type="radio" name="pp_is_scheduled" value="0" <?php if($_SESSION["paper_proof"]["is_scheduled"] == "0") { echo " checked"; }?>></td>
</tr>

// actual proof radio button
<tr valign="top" class="text">
     <td>Is an actual proof scheduled?:</td>
     <td>&nbsp;</td>
     <td>Yes<input onClick="return refreshFocusPage(new_order, 'actual')" type="radio" name="ap_is_scheduled" value="1" <?php if($_SESSION["actual_proof"]["is_scheduled"] == "1") { echo " checked"; }?>>
            &nbsp;No<input onClick="return refreshFocusPage(new_order,  'actual')" type="radio" name="ap_is_scheduled" value="0" <?php if($_SESSION["actual_proof"]["is_scheduled"] == "0") { echo " checked"; }?>></td>
</tr>

// add order button which calls JS function isReady()
<a href="#" onClick="isReady(new_order)"><img src="./images/add_button.gif" width="79" height="28" alt="add" border="0"></a>

// hidden form var and end form
<input type="hidden" name="type">
</form>
new_order.php
-------------------
PHP Code:
<?php
session_start
();
include(
"./functions.php");
$connection connectToDatabase();

// debugging line 1
echo "reached new_order.php<br>";

// put POST vars into SESSION vars

if ($_POST["type"] == "add") {
     
$po_id addOrder();
     
     
// debugging line 2
     
echo " past add order<br>";
     
header("Location: ../orders.php?section=open_orders"); exit -1;
}

else if (
$_POST["type"] == "actual") {
     
// go back to page with anchor selected
     
header("Location: ../orders.php?section=new_order#actual_proof"); exit -1;
}

else if (
$_POST["type"] == "paper") {
     
// go back to page with anchor selected
     
header("Location: ../orders.php?section=new_order#paper_proof"); exit -1;
}

else {
     
// go back to page with saved information

     // debugging line 3
     
echo "at else statement after client select<br>";
     
header("Location: ../orders.php?section=new_order"); exit -1;
}

mysql_close($connection);
?>
Here's a quick run down of the code. There are two radio buttons, paper proof and actual proof, that when selected, the page runs the JS function "refreshFocusPage(form, element)". This function submits the form to new_order.php but instead of adding the order, it saves the POST information in a SESSION and returns the user to the new_order.inc page with the new information.

Ok so now for the problem. If I fill out the order form and do NOT select either of the radio buttons (paper proof or actual proof) the form adds fine, and the debugging statements print out on my screen.

When I select Yes or No for either or both radio buttons, then press the add button, the script at first seems to do nothing. It returns me to the new_order.inc page instead of the open_orders.inc page. However, when I check the db, the order HAS ADDED. But none of my echo statements print out and like I said before it forwards me to an incorrect page.

As I see it this makes absolutely no sense. Why would the script reach the addOrder() function but NOT print out any echo statements?

I hope I've been able to explain the problem without going into too much detail at first. I have obviously left out a lot of code.

I would like to send anyone interested to the web site to see the problem first-hand, however you will need a uname / pw to enter. I can email that information if anyone wishes.

Thanks again.