Problem with $_POST variables.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AaronL
    New Member
    • Jan 2007
    • 99

    Problem with $_POST variables.

    Hello,

    I'm working very hard on an e-commerce package and having severe frustration with it. Something is going wrong with posting variables. I know this is a lot of code but if anyone could help me. The review function and the shipinfo function do not work correctly.

    Code:
      // Process functions passed to the cart.
      switch ($function)
      {
        // Submit shipping information and review the order before checking out.
        case "review":
          if ($_SESSION["ordernumber"]!='')
          {
            // Mame sure country is populated.
            if ($country=='')
            { $country = "United States"; }
            if ($shipcountry=='')
            { $shipcountry = "United States"; }
            
            // Lets see if the same as billing address checkbox was checked.
            // if so, populate the shipping address with the billing address
            // information.
            if ($sameasbilling=='on')
            {
              $shipfirstname = $firstname;
              $shiplastname = $lastname;
              $shipbusinessname = $businessname;
              $shipaddress1 = $address1;
              $shipaddress2 = $address2;
              $shipcity = $city;
              $shipstate = $state;
              $shipzip = $zip;
              $shipcountry = $country;
              $shipprovince = $province;
            }
            
            // Ok, now that we have all of the fields that we need for processing, we
            // need to check all of the required fields to make sure they are not blank,
            // if they are, the user will be redirected back to the shipping information
            // screen with message "Requried fields were left blank."
            if ($firstname=='')
            { $rfblank = true; }
            if ($lastname=='')
            { $rfblank = true; }
            if ($address1=='')
            { $rfblank = true; }
            if ($city=='')
            { $rfblank = true; }
            if (strtolower($country)=='united states' and $state=='')
            { $rfblank = true; }
            if (strtolower($country)=='united states' and $zip=='')
            { $rfblank = true; }
            if ($shipfirstname=='')
            { $rfblank = true; }
            if ($shiplastname=='')
            { $rfblank = true; }
            if ($shipaddress1=='')
            { $rfblank = true; }
            if ($shipcity=='')
            { $rfblank = true; }
            if (strtolower($shipcountry)=='united states' and $shipstate=='')
            { $rfblank = true; }
            if (strtolower($shipcountry)=='united states' and $shipzip=='')
            { $rfblank = true; }
            if ($rfblank)
            { 
              $_SESSION["message"] = 'Required fields were left blank!';
              header('Location: cart.php?fct=shipinfo'); 
            }
            else
            {
              // Now we check to see if this is an international order, if it is, then
              // we set the order total to intnernational order total and remove items from
              // the order that are ineligible for international shipping.
              if (strtolower($shipcountry)!='united states')
              { 
                if ($storeopts['enableintshipping']!=0)
                {
                  // Set the order total to the international order total.
                  $ordertotal = $intordertotal;
              
                  $totalship = $totalintship;
              
                  // If there are any items on the order that are ineligible for international
                  // shipping, then let's remove them from the order.
                  mysql_query("DELETE FROM orderitems WHERE internationalshipping='0' and ordernumber='" . $_SESSION["ordernumber"] . "'");
                }
                else
                {
                  // If international shipping is disabled, then cancel the order.  This shouldn't happen 
                  // because country, should be disabled on the shipping screen as well, but just in case
                  // some freak accident happens to where they get to this page, this will fix it.
                  header('Location: cart.php?fct=co');
                } 
              }
                    
              // Update the order with the customer and shipping information
              $buildsql = mysql_query("UPDATE orders SET firstname='" . $firstname . "', lastname='" . $lastname . "', businessname='" . $businessname . "', address1='" . $address1 . "', 
              address2='" . $address2 . "', city='" . $city . "', state='" . $state . "', zip='" . $zip . "', country='" . $country . "', province='" . $province . "', phone='" 
              . $phone . "', email='" . $email . "', shipfirstname='" . $shipfirstname . "', shiplastname='" . $shiplastname . "', shipbusinessname='" 
              . $shipbusinessname . "', shipaddress1='" . $shipaddress1 . "', shipaddress2='" . $shipaddress2 . "', shipcity='" . $shipcity . "', shipstate='" . $shipstate . "', 
              shipzip='" . $shipzip . "', shipcountry='" . $shipcountry . "', shipprovince='" . $shipprovince . "', subtotal='" . $subtotal . "', tax='" . $tax . "', 
              shipping='" . $totalship . "', ordertotal='" . $ordertotal . "', orderstatus='I' WHERE ordernumber='" 
              . $_SESSION["ordernumber"] . "'");
            
              // Now start building the review order page before checking out.
              echo $htmlheader;
              echo '<body bgcolor="#E0E0E0">
              <center><img src="http://www.ecommphppro.com/' . $companycode . '/images/company/companyheader.jpg" width="800" /></center>
              <table border="0" align="center" width="800" bgcolor="#C0C0C0">
              <tr>
                <td colspan="5" align="left" bgcolor="#FFFFFF">
                  <center><img src="http://www.ecommphppro.com/' . $companycode . '/images/system/orderreviewheader.jpg" /></center>
                </td>
              </tr>
              <tr>
                <td width="100" bgcolor="#C0C0C0"><b>Item Number</b></td>
                <td width="375" bgcolor="#C0C0C0"><b>Product Name</b></td>
                <td width="125" bgcolor="#C0C0C0"><b>Quantity</b></td>
                <td width="100" bgcolor="#C0C0C0"><b>Price</b></td>
                <td width="100" bgcolor="#C0C0C0"><b>Shipping</b></td>
              </tr>';
            
              // Now we retrieve all of the order items and display them in review order.
              $buildsql = mysql_query("SELECT * FROM orderitems WHERE ordernumber='" . $_SESSION["ordernumber"] . "'");
              if (mysql_num_rows($buildsql)>0)
              {
                while ($orderitems = mysql_fetch_array($buildsql))
                {
                  echo '<tr>
                  <td bgcolor="#FFFFFF">
                  ' . $orderitems['itemnumber'] . '
                  </td>
                  <td bgcolor="#FFFFFF">
                  ' . $orderitems['productname'] . '
                  </td>
                  <td bgcolor="#FFFFFF">
                  ' . $orderitems['quantity'] . '
                  </td>
                  <td bgcolor="#FFFFFF">
                  ' . $orderitems['price'] . '
                  </td>
                  <td bgcolor="#FFFFFF">';
                  if (strtolower($shipcountry)!="united states")
                  { echo $orderitems['internationalshipping']; }
                  else
                  { echo $orderitems['shipping']; }
                  echo '</td>
                  </tr>';
                }
              }
              $buildsql = mysql_query("SELECT * FROM orders WHERE ordernumber='" . $_SESSION["ordernumber"] . "' LIMIT 1");
              $orderrec = mysql_fetch_array($buildsql);
              echo '<tr>
                <td colspan="4" bgcolor="#FFFFFF" align="right">
                  <br />
                  <b>Subtotal:</b>
                </td>
                <td bgcolor="#FFFFFF">
                  <br />
                  $' . $orderrec['subtotal'] . '
                </td>
              </tr>
              <tr>
                <td colspan="4" bgcolor="#FFFFFF" align="right">
                  <b>Tax:</b>
                </td>
                <td bgcolor="#FFFFFF">
                  $' . $orderrec['tax'] . '
                </td>
              </tr>
              <tr>
                <td colspan="4" bgcolor="#FFFFFF" align="right">
                  <b>Shipping and Handling:</b>
                </td>
                <td bgcolor="#FFFFFF">
                  $' . $orderrec['shipping'] . '
                </td>
              </tr>
              <tr>
                <td colspan="4" bgcolor="#FFFFFF" align="right">
                  <b><font color="#0000FF">Order Total:</font></b>
                </td>
                <td bgcolor="#FFFFFF">
                  <b>$' . $orderrec['ordertotal'] . '
                </td>
              </tr>
              <tr>
                <td colspan="5" bgcolor="#FFFFFF" align="center">
                  <br />
                  <table bgcolor="#C0C0C0">
                  <tr>
                    <td align="center" colspan="2" width="350">
                      <b>Billing Information</b>
                    </td>
                    <td align="center" colspan="2" width="350">
                      <b>Shipping Information<b>
                    </td>
                  </tr>
                  <tr>
                    <td bgcolor="#FFFFFF" align="right" width="125">
                      <b>Name:</b>
                    </td>
                    <td bgcolor="#FFFFFF">
                    ' . $orderrec['firstname'] . ', ' . $orderrec['lastname'] . '
                    </td>
                    <td bgcolor="#FFFFFF" align="right" width="125">
                      <b>Name:</b>
                    </td>
                    <td bgcolor="#FFFFFF">
                    ' . $orderrec['shipfirstname'] . ', ' . $orderrec['lastname'] . '
                    </td>
                  </tr>
                  <tr>
                    <td bgcolor="#FFFFFF" align="right" width="125">
                      <b>Business Name:</b>
                    </td>
                    <td bgcolor="#FFFFFF">
                    ' . $orderrec['businessname'] . '
                    </td>
                    <td bgcolor="#FFFFFF" align="right" width="125">
                      <b>Business Name:</b>
                    </td>
                    <td bgcolor="#FFFFFF">
                    ' . $orderrec['shipbusinessname'] . '
                    </td>
                  </tr>
                  <tr>
                    <td bgcolor="#FFFFFF" align="right" width="125">
                      <b>Address:</b>
                    </td>
                    <td bgcolor="#FFFFFF">
                    ' . $orderrec['address1'] . '
                    </td>
                    <td bgcolor="#FFFFFF" align="right" width="125">
                      <b>Address:</b>
                    </td>
                    <td bgcolor="#FFFFFF">
                    ' . $orderrec['shipaddress1'] . '
                    </td>
                  </tr>
                  <tr>
                    <td bgcolor="#FFFFFF" align="right" width="125">
                      <b>Address 2:</b>
                    </td>
                    <td bgcolor="#FFFFFF">
                    ' . $orderrec['address2'] . '
                    </td>
                    <td bgcolor="#FFFFFF" align="right" width="125">
                      <b>Address 2:</b>
                    </td>
                    <td bgcolor="#FFFFFF">
                    ' . $orderrec['shipaddress2'] . '
                    </td>
                  </tr>
                  <tr>
                    <td bgcolor="#FFFFFF" align="right" width="125">
                      <b>City/State/Zip:</b>
                    </td>
                    <td bgcolor="#FFFFFF">
                    ' . $orderrec['city'] . ', ' . $orderrec['state'] . ' ' . $orderrec['zip'] . '
                    </td>
                    <td bgcolor="#FFFFFF" align="right" width="125">
                      <b>City/State/Zip:</b>
                    </td>
                    <td bgcolor="#FFFFFF">
                    ' . $orderrec['shipcity'] . ', ' . $orderrec['shipstate'] . ' ' . $orderrec['shipzip'] . '
                    </td>
                  </tr>
                  <tr>
                    <td bgcolor="#FFFFFF" align="right" width="125">
                      <b>Country:</b>
                    </td>
                    <td bgcolor="#FFFFFF">
                    ' . $orderrec['country'] . '
                    </td>
                    <td bgcolor="#FFFFFF" align="right" width="125">
                      <b>Country:</b>
                    </td>
                    <td bgcolor="#FFFFFF">
                    ' . $orderrec['shipcountry'] . '
                    </td>
                  </tr>
                  <tr>
                    <td bgcolor="#FFFFFF" align="right" width="125">
                      <b>Province:</b>
                    </td>
                    <td bgcolor="#FFFFFF">
                    ' . $orderrec['province'] . '
                    </td>
                    <td bgcolor="#FFFFFF" align="right" width="125">
                      <b>Province:</b>
                    </td>
                    <td bgcolor="#FFFFFF">
                    ' . $orderrec['shipprovince'] . '
                    </td>
                  </tr>
                  <tr>
                    <td bgcolor="#FFFFFF" align="right" width="125">
                      <b>Phone:</b>
                    </td>
                    <td bgcolor="#FFFFFF" colspan="3">
                    ' . $orderrec['phone'] . '
                    </td>
                  </tr>
                  <tr>
                    <td bgcolor="#FFFFFF" align="right" width="125">
                      <b>E-Mail:</b>
                    </td>
                    <td bgcolor="#FFFFFF" colspan="3">
                    ' . $orderrec['email'] . '
                    </td>
                  </tr>                                
                  </table>
                  <br />
                </td>
              </tr>
              <tr>
                <td colspan="2" align="left">
                  <a href="http://www.ecommphppro.com/' . $companycode . '/cart.php">
                    <img src="http://www.ecommphppro.com/' . $companycode . '/images/system/backtocart.jpg" border="0" alt="Back to Cart" />
                  </a>
                </td>
                <td colspan="3" align="right">
                  <a href="' . $storeurl . '"><img src="http://www.ecommphppro.com/' . $companycode . '/images/system/continueshopping.jpg" border="0" alt="Back to Store" /></a>
                </td>
              </tr>
              </table></body></html>';
          }
        }
        break; // End of review order.
        
        
        
        
        
        // Enter shipping information.
        case "shipinfo":
          if ($_SESSION["ordernumber"]!='')
          {
            
            // If the user had already entered in shipping information, let's get that back
            // for them instead of having them enter the same information in again (I hate that)
            $buildsql = mysql_query("SELECT * FROM orders WHERE ordernumber='" . $_SESSION["ordernumber"] . "' LIMIT 1");
            $orderrec = mysql_fetch_array($buildsql);
            
            echo $htmlheader;
            
            echo '<body bgcolor="#E0E0E0">
            <center><img src="http://www.ecommphppro.com/' . $companycode . '/images/company/companyheader.jpg" width="800" /></center>
            <form action="http://www.ecommphppro.com/'. $companycode .  '/cart.php?fct=review" method="post">
            <input type="hidden" name="subtotal" value="' . $subtotal . '" />
            <input type="hidden" name="totalship" value="' . $totalship . '" />
            <input type="hidden" name="tax" value="' . $tax . '" />
            <input type="hidden" name="totalintship" value="' . $totalintship . '" />
            <input type="hidden" name="ordertotal" value="' . $ordertotal . '" />
            <input type="hidden" name="intordertotal" value="' . $intordertotal . '" />
            <table border="0" align="center" width="800" bgcolor="#C0C0C0">
            <tr>
              <td colspan="2" align="left" bgcolor="#FFFFFF">
                <center><img src="http://www.ecommphppro.com/' . $companycode . '/images/system/shipinfoheader.jpg" /></center>
              </td>
            </tr>
            <tr>
              <td bgcolor="#FFFFFF" colspan="2">
                <br />
                <b>' . $companyinfo['companyname'] . ' - Order: ' . $_SESSION["ordernumber"] . '</b><br /><br />';
                if (isset($_SESSION["message"]))
                { 
                  echo '<center><font color="#FF0000"><h3><i>' . $_SESSION["message"] . '</i></h3></font></center>'; 
                  unset($_SESSION["message"]);
                }
                echo '<table align="center" bgcolor="#C0C0C0" border="0">
                <tr>
                  <td bgcolor="#FFFFFF" align="right" colspan="6">
                    <i>Required fields marked with: **</i>
                  </td>
                </tr>
                <tr>
                  <td align="center" colspan="6">
                    <b>Billing Address</b>
                  </td>
                </tr>
                <tr>
                  <td bgcolor="#FFFFFF" align="right">
                    <b>First Name</b>*:
                  </td>
                  <td bgcolor="#FFFFFF" align="left" colspan="5">
                    <input type="text" name="firstname" size="45" value="' . $orderrec['firstname'] . '" />
                  </td>
                </tr>
                <tr>
                  <td bgcolor="#FFFFFF" align="right">
                    <b>Last Name</b>*:
                  </td>
                  <td bgcolor="#FFFFFF" align="left" colspan="5">
                    <input type="text" name="lastname" size="45" value="' . $orderrec['lastname'] . '" />
                  </td>
                </tr>
                <tr>
                  <td bgcolor="#FFFFFF" align="right">
                    <b>Business Name</b>:
                  </td>
                  <td bgcolor="#FFFFFF" align="left" colspan="5">
                    <input type="text" name="businessname" size="45" value="' . $orderrec['businessname'] . '" />
                  </td>
                </tr>
                <tr>
                  <td bgcolor="#FFFFFF" align="right">
                    <b>Address</b>*:
                  </td>
                  <td bgcolor="#FFFFFF" align="left" colspan="5">
                    <input type="text" name="address1" size="45" value="' . $orderrec['address1'] . '" />
                  </td>
                </tr>
                <tr>
                  <td bgcolor="#FFFFFF" align="right">
                    <b>Address 2</b>:
                  </td>
                  <td bgcolor="#FFFFFF" align="left" colspan="5">
                    <input type="text" name="address2" size="45" value="' . $orderrec['address2'] . '" />
                  </td>
                </tr>
                <tr>
                  <td bgcolor="#FFFFFF" align="right">
                    <b>City</b>*:
                  </td>
                  <td bgcolor="#FFFFFF" align="left">
                    <input type="text" name="city" size="15" value="' . $orderrec['city'] . '" />
                  </td>
                  <td bgcolor="#FFFFFF" align="right">
                    <b>State</b>*:
                  </td>
                  <td bgcolor="#FFFFFF" align="left">
                    <select name="state">
                    <option value="" selected></option>';
                    
                  // Get available states
                  $buildsql = mysql_query("SELECT * FROM states WHERE enabled='1' ORDER BY stateid");
                  while ($states = mysql_fetch_array($buildsql))
                  { 
                    if ($orderrec['state']==$states['abbreviation'])
                    { echo '<option value="' . $states['abbreviation'] . '" selected>' . $states['abbreviation'] . '</option>' . chr(13); }
                    else
                    { echo '<option value="' . $states['abbreviation'] . '">' . $states['abbreviation'] . '</option>' . chr(13); } 
                  }
                    
                  echo '</select>
                  </td>
                  <td bgcolor="#FFFFFF" align="right">
                    <b>Zip</b>*:
                  </td>
                  <td bgcolor="#FFFFFF" align="left">
                    <input type="text" name="zip" size="5" value="' . $orderrec['zip'] . '" />
                  </td>
                </tr>';
                if ($storeopts['enableintshipping']!=0)
                {
                echo '<tr>
                  <td bgcolor="#FFFFFF" align="right">
                    <b>Country</b>:
                  </td>
                  <td bgcolor="#FFFFFF" align="left">
                  <select name="country">';
                  
                  // Get available countries
                  $buildsql = mysql_query("SELECT * FROM countries WHERE enabled='1' ORDER BY countryid");
                  while ($countries = mysql_fetch_array($buildsql))
                  { 
                    if ($orderrec['country']==$country['countryname'])
                    { echo '<option value="' . $countries['countryname'] . '" selected>' . $countries['countryname'] . '</option>' . chr(13); }
                    else
                    { echo '<option value="' . $countries['countryname'] . '">' . $countries['countryname'] . '</option>' . chr(13); }               
                  }
                  
                  echo '</select>
                  </td>
                  <td bgcolor="#FFFFFF" align="right" colspan="2">
                    <b>Province</b>:
                  </td>
                  <td bgcolor="#FFFFFF" align="left" colspan="2">
                    <input type="text" size="9" name="province" value="' . $orderrec['province'] . '" />
                  </td>
                </tr>';
                }         
                echo '<tr>
                  <td bgcolor="#FFFFFF" align="right">
                    <b>Phone</b>:
                  </td>
                  <td bgcolor="#FFFFFF" align="left" colspan="5">
                    <input type="text" name="phone" size="45" value="' . $orderrec['phone'] . '" />
                  </td>
                </tr>
                <tr>
                  <td bgcolor="#FFFFFF" align="right">
                    <b>E-Mail</b>:
                  </td>
                  <td bgcolor="#FFFFFF" align="left" colspan="5">
                    <input type="text" name="email" size="45" value="' . $orderrec['email'] . '" />
                  </td>
                </tr>
                <tr>
                  <td align="center" colspan="6">
                    <b>Shipping Address</b><br />
                    <input type="checkbox" name="sameasbilling"><b>Same as Billing Address.</b></input>
                  </td>
                </tr>
                <tr>
                  <td bgcolor="#FFFFFF" align="right">
                    <b>First Name</b>*:
                  </td>
                  <td bgcolor="#FFFFFF" align="left" colspan="5">
                    <input type="text" name="shipfirstname" size="45" value="' . $orderrec['shipfirstname'] . '" />
                  </td>
                </tr>
                <tr>
                  <td bgcolor="#FFFFFF" align="right">
                    <b>Last Name</b>*:
                  </td>
                  <td bgcolor="#FFFFFF" align="left" colspan="5">
                    <input type="text" name="shiplastname" size="45" value="' . $orderrec['shiplastname'] . '" />
                  </td>
                </tr>
                <tr>
                  <td bgcolor="#FFFFFF" align="right">
                    <b>Business Name</b>:
                  </td>
                  <td bgcolor="#FFFFFF" align="left" colspan="5">
                    <input type="text" name="shipbusinessname" size="45" value="' . $orderrec['shipbusinessname'] . '" />
                  </td>
                </tr>
                <tr>
                  <td bgcolor="#FFFFFF" align="right">
                    <b>Address</b>*:
                  </td>
                  <td bgcolor="#FFFFFF" align="left" colspan="5">
                    <input type="text" name="shipaddress1" size="45" value="' . $orderrec['shipaddress1'] . '" />
                  </td>
                </tr>
                <tr>
                  <td bgcolor="#FFFFFF" align="right">
                    <b>Address 2</b>:
                  </td>
                  <td bgcolor="#FFFFFF" align="left" colspan="5">
                    <input type="text" name="shipaddress2" size="45" value="' . $orderrec['shipaddress2'] . '" />
                  </td>
                </tr>
                <tr>
                  <td bgcolor="#FFFFFF" align="right">
                    <b>City</b>*:
                  </td>
                  <td bgcolor="#FFFFFF" align="left">
                    <input type="text" name="shipcity" size="15" value="' . $orderrec['shipcity'] . '" />
                  </td>
                  <td bgcolor="#FFFFFF" align="right">
                    <b>State</b>*:
                  </td>
                  <td bgcolor="#FFFFFF" align="left">
                    <select name="shipstate" />
                    <option value="" selected></option>';
                  
                  // Get available states
                  $buildsql = mysql_query("SELECT * FROM states WHERE enabled='1' ORDER BY stateid");
                  while ($states = mysql_fetch_array($buildsql))
                  { 
                    if ($orderrec['shipstate']==$states['abbreviation'])
                    { echo '<option value="' . $states['abbreviation'] . '" selected>' . $states['abbreviation'] . '</option>' . chr(13); }
                    else
                    { echo '<option value="' . $states['abbreviation'] . '">' . $states['abbreviation'] . '</option>' . chr(13); } 
                  }
                  
                  echo '</select>
                  </td>
                  <td bgcolor="#FFFFFF" align="right">
                    <b>Zip</b>*:
                  </td>
                  <td bgcolor="#FFFFFF" align="left">
                    <input type="text" name="shipzip" size="5" value="' . $orderrec['shipzip'] . '" />
                  </td>
                </tr>';
                if ($storeopts['enableintshipping']!=0)
                {
                  echo '<tr>
                  <td bgcolor="#FFFFFF" align="right">
                    <b>Country</b>:
                  </td>
                  <td bgcolor="#FFFFFF" align="left">
                  <select name="shipcountry">';
                  
                  // Get available countries
                  $buildsql = mysql_query("SELECT * FROM countries WHERE enabled='1' ORDER BY countryid");
                  while ($countries = mysql_fetch_array($buildsql))
                  { 
                    if ($orderrec['shipcountry']==$country['countryname'])
                    { echo '<option value="' . $countries['countryname'] . '" selected>' . $countries['countryname'] . '</option>' . chr(13); }
                    else
                    { echo '<option value="' . $countries['countryname'] . '">' . $countries['countryname'] . '</option>' . chr(13); } 
                  }
                  
                  echo '</select>
                  </td>
                  <td bgcolor="#FFFFFF" align="right" colspan="2">
                    <b>Province</b>:
                  </td>
                  <td bgcolor="#FFFFFF" align="left" colspan="2">
                    <input type="text" size="9" name="shipprovince" value="' . $orderrec['shipprovince'] . '" />
                  </td>
                </tr>';
                }                         
                echo '</table>
                <br /><br />
              </td>
            </tr>
            <tr>
              <td align="left" bgcolor="#C0C0C0">
                <a href="http://www.ecommphppro.com/' . $companycode . '/cart.php"><img src="http://www.ecommphppro.com/' 
                . $companycode . '/images/system/backtocart.jpg" border="0" alt="Back to Cart"/></a>
              </td>
              <td align="right" bgcolor="#C0C0C0">
                <a href="' . $storeurl . '"><img src="http://www.ecommphppro.com/' . $companycode . '/images/system/continueshopping.jpg" border="0" /></a>
                <input type="image" src="http://www.ecommphppro.com/' . $companycode . '/images/system/nextbutton.jpg" name="submit" alt="Next" />
              </td>
            </tr>  
            </table></form></body></html>';
          
          }
        break;  // End of enter shipping information
    If you'd like to see what it is doing, go to www.ecommphppro .com/bobspancakes/store.php Add an item to the cart, enter your shipping information, and when you get to the review order, click on the back to store item, add another item to the cart, click next and it should go back to the shipping information screen with all of the info. Then, click next to review the order, you'll get a message that said required fields aren't filled out, go ahead and click next again and it will take you to the review order screen with 0.00 in order totals *AHHHRRRRRRRGGH *. I know this is a lot but I could use the help, my brain is tired, I'm broke, and this is my only hope of any future income...
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    Can I recommend adding some code at the top of all your pages to display the $_SESSION and $_POST variables you're expecting to exist, so that you can trace which page is losing your data.

    If you are not getting any errors (besides the messages you program) then it's not syntax and you will really need to narrow down where there might be a problem.

    If you can locate the page where the data is lost, then echo those variables out at different check points in the code of that page. Doing this you can pinpoint the code block causing the issue and it should be clear how to fix it, or if not: post and we can help.

    Also, "only hope of future income" might be a bit over the top. "Only hope of a future income doing something you like", may be closer to the mark. We all gotta start at the bottom.

    Comment

    • AaronL
      New Member
      • Jan 2007
      • 99

      #3
      Haha, yeah unfortunatly this is my only hope, there isn't really any jobs around here.

      Comment

      • TheServant
        Recognized Expert Top Contributor
        • Feb 2008
        • 1168

        #4
        Originally posted by AaronL
        Haha, yeah unfortunatly this is my only hope, there isn't really any jobs around here.
        No worries, well let us know if you manage to pinpoint where the data loss is occurring.

        Comment

        • AaronL
          New Member
          • Jan 2007
          • 99

          #5
          The weird thing is, sometimes the variables post fine and sometimes it doesn't I echoed the variables out even before any data manipulation happens to them and this happens intermittently. I'm wondering if there is some kind of weird bug with $_POST method that's causing it. My code looks fine. I'm wondering if I should just use session variables for everything here...

          Comment

          • AaronL
            New Member
            • Jan 2007
            • 99

            #6
            I found this:



            I think I'm going to give it a try, I'll let you know.

            Comment

            • AaronL
              New Member
              • Jan 2007
              • 99

              #7
              Yeah that didn't fix it either, weird, yeah, some kind of bug I checked my code everywhere. There isn't anything in the code causing problem, I'm just using a standard form on the shipping information page, and it just intermittently posts blank values, I'm wondering if it has something to do with browser cache data or something... Here is my code that gets the posted values...

              Code:
                // Function to clean malicious posted values for security.
                // Syntax: cleanposted('postedvariable', 'maximum character length');
                function cleanposted($postvalue, $maxlength)
                {
                  // Strip HTML tags from the posted value
                  $cleanvalue = strip_tags($postvalue);
                  
                  // Remove malicious commands and characters from the posted value.
                  $cleanvalue = str_ireplace("select", "", $cleanvalue);
                  $cleanvalue = str_ireplace("update", "", $cleanvalue);
                  $cleanvalue = str_ireplace("delete", "", $cleanvalue);
                  $cleanvalue = str_ireplace("insert", "", $cleanvalue);
                  $cleanvalue = str_ireplace("drop", "", $cleanvalue);
                  $cleanvalue = str_ireplace("<", "", $cleanvalue);
                  $cleanvalue = str_ireplace(">", "", $cleanvalue);
                  $cleanvalue = str_ireplace("+", "", $cleanvalue);
                  $cleanvalue = str_ireplace("*", "", $cleanvalue);
                  $cleanvalue = str_ireplace("%", "", $cleanvalue);
                  $cleanvalue = str_ireplace("\"", "", $cleanvalue);
                  $cleanvalue = str_ireplace("=", "", $cleanvalue);
                  $cleanvalue = str_ireplace("`", "", $cleanvalue);
                  
                  // Cut the posted value down to the maximum length specified.
                  $cleanvalue = substr($cleanvalue, 0, $maxlength);
                  
                  // Return the clean posted value free of exploits!
                  return trim($cleanvalue);
                }
               
                // Get passed variables.
                //$_GET variables
                $function = cleanposted($_GET["fct"], 32);
                $itemnumber = cleanposted($_GET["inum"], 16);
                $quantity = cleanposted($_GET["qty"], 16);
                
                //$_POST variables
                // Get the posted values
                $subtotal = $_POST["subtotal"];
                $tax = $_POST["tax"];
                $totalship = $_POST["totalship"];
                $totalintship = $_POST["totalintship"];
                $ordertotal = $_POST["ordertotal"];
                $intordertotal = $_POST["intordertotal"];
                $firstname = $_POST["firstname"];
                $lastname = $_POST["lastname"];
                $businessname = $_POST["businessname"];
                $address1 = $_POST["address1"];
                $address2 = $_POST["address2"];
                $city = $_POST["city"];
                $state = $_POST["state"];
                $zip = $_POST["zip"];
                $country = $_POST["country"];
                $province = $_POST["province"];
                $phone = $_POST["phone"];
                $email = $_POST["email"];
                $sameasbilling = $_POST["sameasbilling"];
                $shipfirstname = $_POST["shipfirstname"];
                $shiplastname = $_POST["shiplastname"];
                $shipbusinessname = $_POST["shipbusinessname"];
                $shipaddress1 = $_POST["shipaddress1"];
                $shipaddress2 = $_POST["shipaddress2"];
                $shipcity = $_POST["shipcity"];
                $shipstate = $_POST["shipstate"];
                $shipzip = $_POST["shipzip"];
                $shipcountry = $_POST["shipcountry"];
                $shipprovince = $_POST["shipprovince"];
              
                
                $subtotal = cleanposted($subtotal, 16);
                $tax = cleanposted($tax, 16);
                $totalship = cleanposted($totalship, 16);
                $totalintship = cleanposted($totalintship, 16);
                $ordertotal = cleanposted($ordertotal, 16);
                $intordertotal = cleanposted($intordertotal, 16);
                $firstname = cleanposted($firstname, 128);
                $lastname = cleanposted($lastname, 128);
                $businessname = cleanposted($businessname, 128);
                $address1 = cleanposted($address1, 128);
                $address2 = cleanposted($address2, 128);
                $city = cleanposted($city, 128);
                $state = cleanposted($state, 2);
                $zip = cleanposted($zip, 16);
                $country = cleanposted($country, 128);
                $province = cleanposted($province, 128);
                $phone = cleanposted($phone, 16);
                $email = cleanposted($email, 128);
                $sameasbilling = cleanposted($sameasbilling, 3);
                $shipfirstname = cleanposted($shipfirstname, 128);
                $shiplastname = cleanposted($shiplastname, 128);
                $shipbusinessname = cleanposted($shipbusinessname, 128);
                $shipaddress1 = cleanposted($shipaddress1, 128);
                $shipaddress2 = cleanposted($shipaddress2, 128);
                $shipcity = cleanposted($shipcity, 128);
                $shipstate = cleanposted($shipstate, 2);
                $shipzip = cleanposted($shipzip, 16);
                $shipcountry = cleanposted($shipcountry, 128);
                $shipprovince = cleanposted($shipprovince, 128);
              A mystery to me...

              Comment

              • AaronL
                New Member
                • Jan 2007
                • 99

                #8
                Oh and let me add that I even tried taking my cleanposted function completely out of the picture, same issue... I guess the only thing left to do is not let them go back to the store and add more items by the time they get to the review order screen, but that sucks...

                Comment

                • JKing
                  Recognized Expert Top Contributor
                  • Jun 2007
                  • 1206

                  #9
                  I think you have some other issues going on as well.

                  I added two regular pancakes to the cart. Then clicked back to store. I then added 1 medium pancake. Filled in my info and onto the review page. The medium pancake isn't in the list anymore.

                  My subtotal: $18.59
                  My tax: $1.12
                  Shipping and handling: $4.00
                  Order Total: $7.82

                  Comment

                  • AaronL
                    New Member
                    • Jan 2007
                    • 99

                    #10
                    What country did you have selected, if the item isn't eligible for international shipping, it gets removed, I probably should put a message on there for that.

                    Comment

                    • AaronL
                      New Member
                      • Jan 2007
                      • 99

                      #11
                      It's looking like you can't use $_POST variables in this way for some reason, it looks like the browser holds them in the cache and resets them the next time they are called or something. I may just have to put just a cancel order option there or something, I don't know, I'm frustrated beyond belief at this point, I spent so much time developing this software, the rest of the software is incredible and would be a great service to people, you can change your site layout on the fly etc... Too bad when I got to the very end of development I ran into this crap... :(

                      Comment

                      • AaronL
                        New Member
                        • Jan 2007
                        • 99

                        #12
                        I'm working on redesigning the review order section, I see where there are some calculation issues, but still not sure about the post issues...

                        Comment

                        • AaronL
                          New Member
                          • Jan 2007
                          • 99

                          #13
                          Ok, found something interesting...

                          First, I put a line of text in the review order section at the top that says The posted first name is:

                          Now here is the steps you can recreate the problem with

                          Add item to cart:
                          click next
                          enter first name
                          click next
                          you should see your name at the top
                          then click back to cart,
                          click next
                          enter in a different first name
                          click next
                          you'll see that nothing posted.

                          It appears that if a page is in cache, it will not post again when you submit the form. Any way to fix that?

                          Comment

                          • JKing
                            Recognized Expert Top Contributor
                            • Jun 2007
                            • 1206

                            #14
                            Are you setting the hidden inputs on the shipping page?

                            Comment

                            • AaronL
                              New Member
                              • Jan 2007
                              • 99

                              #15
                              Yeah I was, but now I'm just going to recalculate the totals (which were the hidden inputs). I'm having problems even with the inputs that aren't hidden and are just in text boxes, I'll just have to put up with them for now. Don't know how good my software will do in the market though with glitches like that...

                              Comment

                              Working...