Jump to content

Recommended Posts

Hi, I ma trying to change a shopping cart that I have from taking payments through Barclays EPDQ to just sending an email as a "wish list"

 

The below code is a version of the checkout page I normally use (which then takes payment)  I just need it to email the basket and checkout details to me.

 

Can anyone help with the code for this please?

 

Cheers.

 

<?php


//include header code
include_once("head.php");
// use the user_connection include file's connectDB function
include_once("usr_conn.php");
if(!connectDB())
{
	echo "<p>Unable To Connect To Database</p>";

	return;

}	


// assign variables

$currency = "£";



//set form destination

$destination =  "./upload/save_customer.php";   // "mailform.php";//



// start the html table

?>
<script language="JavaScript" src="../validation.js"></script>
<!--  start header graphic html -->
<style type="text/css">
<!--
style3 {
font-size: 10px;
font-family: Verdana, Arial, Helvetica, sans-serif;
}
style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
color: #990000;
}
.style1 {
font-family: Arial, Helvetica, sans-serif;
color: #990000;
}
-->
</style>

<link href="style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style2 {color: #990000}
.style3 {font-size: 10px}
.warning {
color: #900;
font-family: Verdana, Geneva, sans-serif;
}
-->
</style>

<table width="950" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr> 
    <td background="../images/back.gif"> </td>
  </tr>
</table>
<table width="950" border="0" align="center" cellpadding="15" cellspacing="0" bgcolor="#FFFFFF">
  <tr> 
    <td height="170" valign="top" background="../images/back.gif"> <div align="center">
      <form action="<?php echo $destination; ?>" method=POST>
        <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0"> 
        <tr> 
          <td><div align="center"></div></td>
        </tr>
        <tr> 
          <td align=center> 
            <!--begin basket output-->
            <table width="100%" border="1" cellpadding="2" cellspacing="0" bordercolor="#FFFFFF">
              <!--start tableheaders-->
              <tr class="headertable">
                <td colspan=5><font class=bigheader>ORDER DETAILS:</font></td>
              </tr>
              <tr class="headertable"> 
                <td height="25"> <div align="center">CAR MAKE</div></td>
                <td height="25"> <div align="center">PRODUCT TYPE</div></td>
                <td height="25"> <div align="center">PRODUCT MAKE</div></td>
                <td height="25"> <div align="center">REF. NO.</div></td>
                <td height="25"> <div align="center">QTY</div></td>
              </tr>
              <!--end table headers-->
              <?php





	//get info from shopper table

	$sqlquery = "SELECT * FROM shopper WHERE user_ID = '" . $userID . "'";

	$result = mysql_query($sqlquery);

	$rowCount = mysql_num_rows($result);		



	// if no matches then nothing to checkout

	if ($rowCount == 0)

	{

			echo ("<p><font class=error>Your basket is empty. Either you have come to this page in error or you may need to check your cookie settings and make sure that you have cookies enabled within your browser settings.<br>Please go back to the shopping basket.</font></p>");

			return;	

	}

	else 

	{		//store shopper details	

			$shoprow = mysql_fetch_assoc($result);

			$Basket_total = number_format(htmlspecialchars($shoprow['Basket_total']), 2);



			//echo "tot: " . $Basket_total;

			$Postage = htmlspecialchars($shoprow['Postage']);

			//get basket details 

			$sqlquery = "SELECT * FROM basket WHERE userID = '" . $userID . "'";

			$result = mysql_query($sqlquery);

			$rowCount = mysql_num_rows($result);

			if ($rowCount == 0)

			{

			echo "<font class=error><p>Error: Your basket was empty.</p></font>";

			return;

			}

			else

			{

				// select the userID's basket query and the Product Reference relating to each of the basket's productID's	

				$sqlquery = "SELECT * FROM basket INNER JOIN products ON basket.productID = products.Prod_ID WHERE ((basket.userID) = '" . $userID . "')";

				//echo $sqlquery;

				$baskresult = mysql_query($sqlquery);	

				$rowCount = mysql_num_rows($baskresult);	



				//set counter to name each hidden form element for the product details

				$frmCount = 1;



				while ($row = mysql_fetch_assoc($baskresult))

				{



	 			//cut the prod_type variable

				//get the length of the variable

				$strLength = strlen ($row["Prod_Type"]);

				//assign first 2 characters of variable

				$strPrefix = substr($row["Prod_Type"], 0, 2);

				//debug

				//echo "\n prefix :" . $strPrefix;

				//assign remaining characters of variable

				$strSuffix = substr($row["Prod_Type"], 2, $strLength);

				//debug

				//echo "\n suffix :" . $strSuffix;





				//set product header image depending on the Prod_Type Code

				//start the table row



			switch ($strPrefix)

				{ 		   

			case "BH":
				//$strProdType = "Bulkhead";
				$strProdType = "Vehicle Accessory";

				break;			
			case "DG":

	      

				$strProdType = "Dog Guard";



				break;			




	        

			case "RB":

				//$strProdType = "Roof Bar";
				$strProdType = "Vehicle Accessory";

			    break;



			case "XD":



				$strProdType = "General Accessory";



			    break;




				case "XL":



				$strProdType = "General Accessory";



			    break;



		   case "WG":



				$strProdType = "Window Grille";



			    break;







				 case "BT":



				$strProdType = "Boot Rack";



			    break;







				 case "BR":



				$strProdType = "Bike Rack";



			    break;








				 case "LB":



				$strProdType = "Roof Bar";



			    break;







				 case "LR":



				$strProdType = "Roof Rack";



			    break;







				 case "SK":



				$strProdType = "Ski Rack";



			    break;



				 case "VR":



				$strProdType = "Van Racking";



			    break;









		   

		   default:

		   		

				$strProdType = "The product type for this item could not be found";

	}	 

				$color="#E9E9E9";

				echo("<tr class=stdtable><td align=center bgcolor=$color> " . htmlspecialchars($row['Car_Make']) . " " . "</td>");

				echo("<td align=center bgcolor=$color> " . $strProdType . " " . "</td>");

				echo("<td align=center bgcolor=$color> " . htmlspecialchars($row['Prod_Make']) . " " . "</td>");

				echo("<td align=center bgcolor=$color> " . htmlspecialchars($row['Prod_REF']) . " " . "</td>");

				echo("<td align=center bgcolor=$color>". htmlspecialchars($row['quantity']) ."</td></tr>");

				//create hidden form names and values containing product details
				echo "<input type=hidden name=Car".$frmCount."_Make value=\"". htmlspecialchars($row['Car_Make']) ."\">";





				echo "<input type=hidden name=Car".$frmCount."_Model value=\"". htmlspecialchars($row['Car_Model']) ."\">";





				echo "<input type=hidden name=Product".$frmCount."_Make value=\"". htmlspecialchars($row['Prod_Make']) ."\">";

				echo "<input type=hidden name=Product".$frmCount."_Model value=\"". htmlspecialchars($row['Prod_Model']) ."\">";

				echo "<input type=hidden name=Product".$frmCount."_Type value=\"". $strProdType ."\">";

				echo "<input type=hidden name=Product".$frmCount."_REF value=\"". $row['Prod_REF'] ."\">";

				echo "<input type=hidden name=Product".$frmCount."_Quantity value=\"". htmlspecialchars($row['quantity']) ."\">";





				$bob = number_format(calcVAT(htmlspecialchars($row['Price_ExVat'])), 2);





				echo "<input type=hidden name=Product".$frmCount."_Price value=\"". $bob ."\">";

				//incrementcount by 1

				$frmCount ++;

				}//end while



				echo("<tr class=stdtable><td colspan=3> </td><td align=center><b>TOTAL</b></td><td align=center>" . $currency . $Basket_total . "</td></tr>");



			}//end else

	}//end else					

?>
            </table>
            <hr align="center" width="600" size="1" /> <table width="600" border="0" cellspacing="0" cellpadding="2">
              <tr> 
                <td><strong><font size="2" face="Arial, Helvetica, sans-serif">Your 
                  Contact Details</font></strong></td>
              </tr>
            </table>
            <table width="606" border="0" cellspacing="0" cellpadding="3">
              <tr> 
                <td width="137"><div align="right"><font face="Arial, Helvetica, sans-serif" size="2">Title*</font></div></td>
                <td width="173"> <select name="title">
                    <option selected>Mr.</option>
                    <option>Mrs</option>
                    <option>Miss</option>
                  </select></td>
                <td width="278"> </td>
              </tr>
              <tr> 
                <td width="137" class="small"><div align="right"><font face="Arial, Helvetica, sans-serif" size="2">First 
                    Name*</font></div></td>
                <td width="173"><font face="Arial, Helvetica, sans-serif" size="2"><span class="bodytext"> 
                  <input type="text" name="Customer_Name" size="40" maxlength="50" style=" WIDTH:160px; background-color: #F4F0F5; color: #000000; font-family: Verdana; font-size: 8pt; font-weight: regular; border-color: #ffffff" />
                  </span></font></td>
                <td width="278"> </td>
              </tr>
              <tr> 
                <td width="137" class="small"><div align="right"><font face="Arial, Helvetica, sans-serif" size="2">Surname*</font></div></td>
                <td width="173"><font face="Arial, Helvetica, sans-serif" size="2"><span class="bodytext"> 
                  <input type="text" name="Customer_Surname" size="40" maxlength="50" style=" WIDTH:160px; background-color: #F4F0F5; color: #000000; font-family: Verdana; font-size: 8pt; font-weight: regular; border-color: #ffffff" />
                  </span></font></td>
                <td width="278"> </td>
              </tr>
              <tr> 
                <td class="small"><div align="right"><font size="2" face="Arial, Helvetica, sans-serif">Business 
                    Name </font></div></td>
                <td><span class="bodytext"> 
                  <input type="text" name="Business_name" size="40" maxlength="50" style=" WIDTH:160px; background-color: #F4F0F5; color: #000000; font-family: Verdana; font-size: 8pt; font-weight: regular; border-color: #ffffff" />
                  </span></td>
                <td> </td>
              </tr>
              <tr> 
                <td width="137" class="small"><div align="right"><font face="Arial, Helvetica, sans-serif" size="2">Address*</font></div></td>
                <td width="173"><span class="bodytext"> 
                  <input type="text" name="Customer_Address1" size="40" maxlength="50" style=" WIDTH:160px; background-color: #F4F0F5; color: #000000; font-family: Verdana; font-size: 8pt; font-weight: regular; border-color: #ffffff" />
                  </span></td>
                <td width="278"> </td>
              </tr>
              <tr> 
                <td width="137"><div align="right"></div></td>
                <td width="173"><span class="bodytext"> 
                  <input type="text" name="Customer_Address2" size="40" maxlength="50" style=" WIDTH:160px; background-color: #F4F0F5; color: #000000; font-family: Verdana; font-size: 8pt; font-weight: regular; border-color: #ffffff" />
                  </span></td>
                <td width="278"> </td>
              </tr>
              <tr> 
                <td width="137"><div align="right"></div></td>
                <td width="173"><span class="bodytext"> 
                  <input type="text" name="Customer_Address3" size="40" maxlength="50" style=" WIDTH:160px; background-color: #F4F0F5; color: #000000; font-family: Verdana; font-size: 8pt; font-weight: regular; border-color: #ffffff" />
                  </span></td>
                <td width="278"> </td>
              </tr>
              <tr> 
                <td width="137" class="small"><div align="right"><font face="Arial, Helvetica, sans-serif" size="2">Town/City*</font></div></td>
                <td width="173"><span class="bodytext"> 
                  <input type="text" name="Customer_Town" size="40" maxlength="50" style=" WIDTH:160px; background-color: #F4F0F5; color: #000000; font-family: Verdana; font-size: 8pt; font-weight: regular; border-color: #ffffff" />
                  </span></td>
                <td width="278"> </td>
              </tr>
              <tr> 
                <td width="137" class="small"><div align="right"><font face="Arial, Helvetica, sans-serif" size="2">County*</font></div></td>
                <td width="173"><span class="bodytext"> 
                  <input type="text" name="Customer_County" size="40" maxlength="50" style=" WIDTH:160px; background-color: #F4F0F5; color: #000000; font-family: Verdana; font-size: 8pt; font-weight: regular; border-color: #ffffff" />
                  </span></td>
                <td width="278"> </td>
              </tr>
              <tr> 
                <td width="137" class="small"><div align="right"><font face="Arial, Helvetica, sans-serif" size="2">Postcode*</font></div></td>
                <td width="173"><span class="bodytext"> 
                  <input type="text" name="Customer_Postcode" size="40" maxlength="50" style=" WIDTH:160px; background-color: #F4F0F5; color: #000000; font-family: Verdana; font-size: 8pt; font-weight: regular; border-color: #ffffff" />
                  </span></td>
                <td width="278"> </td>
              </tr>
              <tr> 
                <td width="137" class="small"><div align="right"><font size="2" face="Arial, Helvetica, sans-serif">Email*</font></div></td>
                <td width="173"><span class="bodytext"> 
                  <input type="text" name="Customer_Email" size="40" maxlength="50" style=" WIDTH:160px; background-color: #F4F0F5; color: #000000; font-family: Verdana; font-size: 8pt; font-weight: regular; border-color: #ffffff" />
                  </span></td>
                <td width="278"> </td>
              </tr>
              <tr bgcolor="#EAEADB"> 
                <td width="137" class="small"> <div align="right"><font face="Arial, Helvetica, sans-serif" size="2">Daytime 
                    Telephone Number*</font></div></td>
                <td width="173"><span class="bodytext"> 
                  <input type="text" name="Customer_Tel" size="40" maxlength="50" style=" WIDTH:160px; background-color: #F4F0F5; color: #000000; font-family: Verdana; font-size: 8pt; font-weight: regular; border-color: #ffffff" />
                  </span></td>
                <td width="278"> </td>
              </tr>
              <tr> 
                <td width="137" class="small"><div align="right"><font face="Arial, Helvetica, sans-serif" size="2">Mobile</font></div></td>
                <td width="173"><span class="bodytext"> 
                  <input type="text" name="Customer_Mobile" size="40" maxlength="50" style=" WIDTH:160px; background-color: #F4F0F5; color: #000000; font-family: Verdana; font-size: 8pt; font-weight: regular; border-color: #ffffff" />
                  </span></td>
                <td width="278"> </td>
              </tr>
            </table>
            <hr align="center" width="600" size="1" />
            <tr>
                <td width="269"> </td>
                <td width="51"> </td>
                <td width="268"> </td>
              </tr>
          <tr>
                
            <table width="600">
              <input type=hidden name="Total_Price" value="<?php echo $Basket_total; ?>" />
              <?php

				//create a shortened version of the userID for quick reference

				$strShortUserID = substr($userID, 0, 6);

				//echo $strShortUserID;

			?>
              <input type=hidden name="Shopper_ID" value="<?php echo $strShortUserID; ?>" />
              <input type=hidden name="User_ID" value="<?php echo $userID; ?>" />
              <input type=hidden name="Postage_Rate" value="<?php echo $Postage; ?>" />
              <tr> 
                <td width="597"><hr width="590" size="1" /></td>
              </tr>
              <tr align="center"> 
                <td class="small"><font face="Arial, Helvetica, sans-serif" size="2"> 
                  <input type="submit" name="epdq" value="send wishlist" style="background-color: #cccccc; color: #000000; font-family: Verdana; font-size: 8pt; border-color: #ffffff"  />
                  
                  </font></td>
              </tr>
            </table>
    </form>
      <!--end basket output-->
    </div></td>
  </tr>
</table>
<hr size="1" /></td>
</tr>
<!--end basket htm-->
<?php

//include footer code







//release the postage resultset array



mysql_free_result($result);



// close the wykes database connection



mysql_close();

?>

Link to comment
https://forums.phpfreaks.com/topic/255594-changing-a-working-basket-to-a-wishlist/
Share on other sites

You have a form with the data that you want, you need to process that form data and make an email body with the field names and values. Where exactly are you stuck at in doing that?

 

To see what your form is sending, use the following line in your form processing code -

 

echo '<pre>',print_r($_POST,true),'</pre>';

 

Your code is horrifically formated. You need to both remove the excess white-space in it and validate the resulting HTML page.

 

Your switch/case logic can be greatly simplified by using a 'lookup' table. Add something like the following to your 'configuration' data -

<?php
// lookup table of product codes and product categories
$product_lookup["BH"] = "Vehicle Accessory";
$product_lookup["DG"] = "Dog Guard";
$product_lookup["RB"] = "Vehicle Accessory";
$product_lookup["XD"] = "General Accessory";
$product_lookup["XL"] = "General Accessory";
$product_lookup["WG"] = "Window Grille";
$product_lookup["BT"] = "Boot Rack";
$product_lookup["BR"] = "Bike Rack";
$product_lookup["LB"] = "Roof Bar";
$product_lookup["LR"] = "Roof Rack";
$product_lookup["SK"] = "Ski Rack";
$product_lookup["VR"] = "Van Racking";

 

Then your switch/case logic will simply become the following and you won't need to alter the body of your code to change, add, or remove any of the categories -

<?php
		if(isset($product_lookup[$strPrefix])){
			$strProdType = $product_lookup[$strPrefix];
		} else {
			$strProdType = "The product type for this item could not be found";
		}

 

You should also use arrays for the repeating form fields so that you can simply iterate over the repeated fields using a foreach loop. See the following -

<?php
		//create hidden form names and values containing product details
		echo "<input type='hidden' name='Car_Make[$frmCount]' value='". htmlspecialchars($row['Car_Make']) ."'>";
		echo "<input type='hidden' name='Car_Model[$frmCount]' value='". htmlspecialchars($row['Car_Model']) ."'>";
		echo "<input type='hidden' name='Product_Make[$frmCount]' value='". htmlspecialchars($row['Prod_Make']) ."'>";
		echo "<input type='hidden' name='Product_Model[$frmCount]' value='". htmlspecialchars($row['Prod_Model']) ."'>";
		echo "<input type='hidden' name='Product_Type[$frmCount]' value='". $strProdType ."'>";
		echo "<input type='hidden' name='Product_REF[$frmCount]' value='". $row['Prod_REF'] ."'>";
		echo "<input type='hidden' name='Product_Quantity[$frmCount]' value='". htmlspecialchars($row['quantity']) ."'>";
		$bob = number_format(calcVAT(htmlspecialchars($row['Price_ExVat'])), 2);
		echo "<input type='hidden' name='Product_Price[$frmCount]' value='$bob'>";

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.