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.
Expand|Select|Wrap|Line Numbers
- // 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