php coding problem, from a newcomer
I'm new to php and cannot figure out how to link a form to a cart button. I first built the form as follows:
<div id="gcwheel_selectorbox"> <table cellpadding="0" cellspacing="0" border="0" width="100%"> <tr><td width="125" valign="bottom" align="center"> <form name="pats_giftcards_12_ATC" method="POST" action="<?php echo $_SERVER["PHP_SELF"]; ?><?php echo (isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] != "")?"?".htmlentities($_SERVER["QUERY_STRING"]):""; ?>"> <br/><table width="227" height="227"><tr> <td colspan="2" align="center"><img src="../images/gift_cards/pats gift card.jpg" alt="gc"><br/><img src="/images/pix.gif" height="2" width="125" alt="*"><br/></td></tr><tr> <td colspan="2" align="center"><a class="styleInfo" ="">Pats Gift Cards</a></td></tr><tr><td colspan="2" align="center"><span>Select Gift Card Amount</span><br /> <SELECT name="pats_giftcards_12_ATC"> <OPTION value="5">$5.00</OPTION> <OPTION value="10">$10.00</OPTION> <OPTION value="15">$15.00</OPTION> <OPTION value="20">$20.00</OPTION> <OPTION value="25">$25.00</OPTION> <OPTION value="30">$30.00</OPTION> <OPTION value="35">$35.00</OPTION> <OPTION value="40">$40.00</OPTION> <OPTION value="45">$45.00</OPTION> <OPTION value="50">$50.00</OPTION> <OPTION value="55">$55.00</OPTION> <OPTION value="60">$60.00</OPTION> <OPTION value="65">$65.00</OPTION> <OPTION value="70">$70.00</OPTION> <OPTION value="75">$75.00</OPTION> <OPTION value="80">$80.00</OPTION> <OPTION value="85">$85.00</OPTION> <OPTION value="90">$90.00</OPTION> <OPTION value="95">$95.00</OPTION> <OPTION value="100" selected>$100.00</OPTION> <OPTION value="120">$120.00</OPTION> <OPTION value="125">$125.00</OPTION> <OPTION value="130">$130.00</OPTION> <OPTION value="150">$150.00</OPTION> <OPTION value="160">$160.00</OPTION> <OPTION value="175">$175.00</OPTION> <OPTION value="200">$200.00</OPTION> <OPTION value="225">$225.00</OPTION> <OPTION value="250">$250.00</OPTION> <OPTION value="300">$300.00</OPTION> <OPTION value="350">$350.00</OPTION> <OPTION value="375">$375.00</OPTION> <OPTION value="400">$400.00</OPTION> <OPTION value="500">$500.00</OPTION> </SELECT><INPUT type="hidden" name="" value="0" /> <img alt="" border="0" src="" width="1" height="1"></td></tr><tr> <td width="72"> </td> <td width="143"></td></tr></table></form></td> </table><p></p> <td valign="top" align="center"> </td>
The cart button is as follows;
<form name="pats_giftcards_12_ATC_<?php echo $pats_giftcards->DisplayInfo(""); ?>" method="POST" action="<?php echo $_SERVER["PHP_SELF"]; ?><?php echo (isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] != "")?"?".htmlentities($_SERVER["QUERY_STRING"]):""; ?>"> <input type="hidden" name="pats_giftcards_12_ID_Add" value="<?php echo $row_products['ProductID']; ?>" > <input type="text" name="pats_giftcards_12_Quantity_Add" value="1" size="4" > <input type="image" value="Add to Cart" name="pats_giftcards_12_ATC" src="../WA_eCart/Images/Pacifica/Btn4_EN_addtocart.gif" border="0"> </form> </div><!--gcwheel end div-->
I then tried to link the button tothe form but I do not know enough about php to get it to work properly in my testing server. When I test the page it lets me select a gift card value from the drop down menu but when Im redirected to the my cart to preview my order it is incorrect, no matter what giftcard denomination I select it always shows me the first card value in the record set of which is a $5.00 gift card. the following code is printed at the top of my giftcard>php page:
<?php //WA eCart Include require_once("../WA_eCart/pats_giftcards_PHP.php"); ?> <?php require_once('../Connections/gcards.php'); ?> <?php $pats_giftcards->GetContent(); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } ?> <?php mysql_select_db($database_gcards, $gcards); $query_products = "SELECT ProductID, ProductName, ProductPrice, ProductCartDesc, ProductShortDesc, ProductLongDesc, ProductThumb, ProductImage FROM products ORDER BY ProductID ASC"; $products = mysql_query($query_products, $gcards) or die(mysql_error()); $row_products = mysql_fetch_assoc($products); $totalRows_products = mysql_num_rows($products); ?>
and further down the page:
?> <?php // WA eCart AddToCart if (isset($_POST["pats_giftcards_12_ATC"]) || isset($_POST["pats_giftcards_12_ATC_x"])) { $ATC_itemID = $_POST["pats_giftcards_12_ID_Add"]; $ATC_AddIfIn = 0; $ATC_RedirectAfter = "cart.php"; $ATC_RedirectIfIn = ""; $ATC_itemName = "".$row_products['ProductName'] ."";// column binding $ATC_itemDescription = "".$row_products['ProductName'] ."";// column binding $ATC_itemThumbnail = "";// column binding $ATC_itemWeight = floatval("0");// column binding $ATC_itemQuantity = "".$_POST["pats_giftcards_12_Quantity_Add"] ."";// column binding $ATC_itemPrice = floatval("".$row_products['ProductPrice'] ."");// column binding $ATC_itemQuantity = floatval($ATC_itemQuantity); if (is_numeric($ATC_itemQuantity) && $ATC_itemQuantity != 0) { $pats_giftcards->AddToCart($ATC_AddIfIn, $ATC_RedirectIfIn, $ATC_itemID, $ATC_itemName, $ATC_itemDescription, $ATC_itemThumbnail, $ATC_itemWeight, $ATC_itemQuantity, $ATC_itemPrice); if ($ATC_RedirectAfter != "" && $pats_giftcards->redirStr == "") { $pats_giftcards->redirStr = $ATC_RedirectAfter; } if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != "") { $_SESSION['WAEC_ContinueRedirect'] = $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']; } else { $_SESSION['WAEC_ContinueRedirect'] = $_SERVER['PHP_SELF']; } } } ?> <?php // WA eCart Redirect if ($pats_giftcards->redirStr != "") { if (function_exists("rel2abs")) $pats_giftcards->redirStr = rel2abs($pats_giftcards->redirStr,dirname(__FILE__)); header("Location: ".$pats_giftcards->redirStr); die(); } ?> any insight would be greatly appreciated.
So again I would like to offer my customers the ability to buy gift cards from my website and so I built a form holding all the card value choices from $5.00 to $500.00 dollars. I then built a record set opened it in dreamweaver cs6 and set bindings to the Giftcard choices in The id, description and price collums. I am using ecart by the way and when I upload to my testing server the following experience occurs; I am able to scroll thru my dropdown menu and select a giftcard by Value and when I select it and hit the add to cart button it sends me to the cart page however the giftcard that it is saying that I selected id always the first card in the record set of which is the $5.00 card. It seems that something is missing in my coding in connecting the cart button to my form so I always get the first card choice in my record set.