Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Repeat Submitting Form In Javascript?

innerHTML

  • Please log in to reply
2 replies to this topic

#1 Cyberen

Cyberen

    CC Regular

  • Member
  • PipPipPip
  • 41 posts

Posted 30 April 2012 - 01:26 PM

Hi there,
I have a question. I have a product page interface in PHP and I recently wanted to add a quantity button to the item, and it's there but non-functional.

The problem now is to make it put multiples of the same item in the shopping cart on the next page. But I don't know how to turn the submission javascript on line 3:

  echo '<td colspan="7" align="right">';
  echo  '<img src="images/addtocart.png" hspace="4"  onclick="';
  echo 'document.form1.submit();">';
  echo '</td>';


into a script that says "take this form and process it however many times the drop-down menu dictates". The number of times selected by the code below:

echo '<td valign=top align=center><img src="images/Quantity.png" border=0></a><br /><select
  name="quantity">
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
  <option value="6">6</option>
  <option value="7">7</option>
  <option value="8">8</option>
  <option value="9">9</option>';
  echo '</select></td>';

which I've turned the result into PHP via this: $quantityofitems = $_POST['quantity'];

So what javascript should I use so it's like the customer refreshed this page and submitted it X more times?

The entirety of the code is seen below, any help would be immensely appreciated!

<?
ini_set('display_errors',1);
ini_set('error_reporting', E_ALL);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors','Off');
include 'db.php';
if (!isset($_POST['action']))
{
//If not isset -> set with dumy value
$_POST['action'] = "undefine";
}
session_start();
header("Cache-control: private");
//add to cart
if($_POST['action']=='add'){
  if(!isset($_SESSION['cart'])){
    $_SESSION['cart']=array();
  }
  $item=$_POST['id'] . '||';
  $item.=$_POST['glass'] . '||';
  $item.=$_POST['finishes'] . '||';
  $item.=$_POST['stocks'] . '||';
  $item.=$_POST['cord_colors'] . '||';
  $item.=$_POST['ceiling'] . '||';
  $item.=$_POST['glass_shape'] . '||';
  $item.=$_POST['leafs'] . '||';
  //$item.=$_POST['quantity'] . '||';
  $item.=$_POST['ceil_cap'];
  array_push($_SESSION['cart'],$item);
  header("Location: viewcart2.php?back=" . urlencode("pro.php?id=" . $_POST['id']));
  exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Example</title>
<link rel="stylesheet" href="NewVersion.css" type="text/css">
<link rel="icon" type="image/ico" href="../images/favicon.ico" />
<script src="rollovers.js" type="text/javascript"></script>
<!--<base href="http://65.110.93.202">-->
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
loadImage1 = new Image();
loadImage1.src = "images/topbuttons/name2.png";
staticImage1 = new Image();
staticImage1.src = "images/topbuttons/name1.png";
// End -->
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-6579606-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();
</script>
<script type="text/javascript">
<!--
var timeout			  = 500;
var closetimer  = 0;
var ddmenuitem    = 0;
// open hidden layer
function mopen(id)
{
// cancel close timer
mcancelclosetime();
// close old layer
if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
// get new layer and show it
ddmenuitem = document.getElementById(id);
ddmenuitem.style.visibility = 'visible';
}
// close showed layer
function mclose()
{
if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}
// go close timer
function mclosetime()
{
closetimer = window.setTimeout(mclose, timeout);
}
// cancel close timer
function mcancelclosetime()
{
if(closetimer)
{
  window.clearTimeout(closetimer);
  closetimer = null;
}
}
// close layer when click-out
document.onclick = mclose;
// -->
</script>
<script>
function openWindow(url,name,height,width){
  var w = window.open (url, name,"height="+height+",width="+width+",left=50,top=50,screenX=50,screenY=50");
}
</script>
<title>Welcome</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){
    if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];
    }
  }
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
  if ((x=MM_findObj(a[i]))!=null){
    document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];
  }
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function fixprice() {
  if(document.form1.ceiling.value.indexOf('|')>0){
    var v = document.form1.ceiling.value.substring(document.form1.ceiling.value.indexOf('|')+1);
    var v2 = v.substring(v.indexOf('|')+1);
var v = v.substring(0,v.indexOf('|'));
    if(document.getElementById('price')){
   document.getElementById('price').innerHTML='<strong> $' + v;
}
    if(document.getElementById('retail')){
		  document.getElementById('retail').innerHTML='<!--<strong> <strike>$' + v2 + '</strike>-->';
    }
  }
}
function change_glass(sColor){
  var i=0;
  for(i=0;i<100;i++){
    if(document.form1.glass.options[i].value==sColor){
		  document.form1.glass.options[i].selected = true;
		  break;
}
  }
}
//-->
</script>
<script type="text/javascript" src="Scripts/dropdownscript.js"></script>
</head>
<body>
<!-- Customization Code -->
<!-- Remove leading // to activate custom variables -->
<script language="Javascript">
//var DOCUMENTGROUP='';
//var DOCUMENTNAME='';
//var ACTION='';
</script>
<!-- End of Customization Code -->
<script type="text/javascript"
src="http://slideshow.triptracker.net/slide.js"></script>
<div id="container">
<div id="header">
    <br class="clearfloat" />
<table><tr><td align="left">
<a href="index.html" onmouseover="image1.src=loadImage1.src;" onmouseout="image1.src=staticImage1.src;">
<img name="image1" src="images/topbuttons/name1.png" border=0></a>
</td><td align="right"><img src="../images/topbuttons/phone.gif" alt="1-866-JEZEBEL" /></td></tr>
<tr><td align="center" colspan="2">
<script type="text/javascript">
var menu=new menu.dd("menu");
menu.init("menu","menuhover");
</script>
</td></tr></table>
		  <!-- end #header --></div>
<?
/* Display categories */
$query = "SELECT id,category,description from categories where id!=11 and deleted=0 order by category";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
$last=0;
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
  if($last>0){
    ?>
    <!--&nbsp;|&nbsp;-->
    <?
    }
    ?>
    <!--<a href="cat.php?id=<?= $line['id'] ?>" class="sub"><?= $line['category']
    ?></a>-->
    <?
    if($_GET['id']==$line['id'] || $last==0){
		  $description=stripslashes($line['description']);
		  $title=stripslashes($line['category']);
		  $last=$line['id'];
    }
  }
  if(isset($_GET['id'])){
$last=$_GET['id'];
}
mysql_free_result($result);
//get product details and convert them into local variables
$query = "SELECT * from products where deleted=0 and id=" . $_GET['id'];
$result = mysql_query($query) or die("Query failed : " . mysql_error());
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
  $name = stripslashes($line['name']);
  $description = stripslashes($line['description']);
  $retail = stripslashes($line['retail']);
  $price = stripslashes($line['price']);
  $bulb = stripslashes($line['bulb']);
  $redirect = stripslashes($line['redirect']);
  $ceiling = stripslashes($line['ceiling']);
  $dims = stripslashes($line['dims']);
  $static = stripslashes($line['static']);
}
mysql_free_result($result);
$ironshape="IronShape";
if(($_GET['id']==1035)||($_GET['id']==1036)||($_GET['id']==1037)||($_GET['id']==1038))
{$ironshape="HoleSize";}
$colorsetname = "Signature";
if ((isset($name))&&((substr($name,14,8)=="Radiance")||(substr($name,0,8)=="Radiance")||(substr($name,8,8)=="Radiance")))
{$viewcol=5;
$colorsetname = "Radiance";}
else {$viewcol=6;}
$ispendant = 16;
$redirviewcol = ($viewcol+999);
?>
				    &nbsp;&nbsp;<table height="530" width="890" border="0" cellpadding="4" cellspacing="0">
						  <tr>
						    <td width="560" height="371" align="middle" valign="middle">
								  <img name="mainimg" id="mainimg" src="<?
//get main image
$query = "SELECT * from glass where deleted=0 and pid=" . $_GET['id'] . " order by color limit 1";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
   echo $line['url'];
}
mysql_free_result($result);
?>" >
<!-- width="263" height="353" --></td><? if(($_GET['id']==1004)||($_GET['id']==1005))
{echo '</tr><tr>';}?>
   <td valign="middle" align ="center"><table border="0" cellpadding="0" cellspacing="0">
		 <tr>
		   <td valign="top" align="center"><? if($_GET['id']!=14){ ?>
				   <table width="239" border="0" cellspacing="0" cellpadding="0">
						 <?
$colorofswatchy=$_POST['color'];
$narrows=3;
if(($_GET['id']==1004)||($_GET['id']==1005))
{$narrows=5;}
//This is for the main views of the product colors
//get glass color
$query = "SELECT * from glass where deleted=0 and pid=" . $_GET['id'] . " order by color";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
if(mysql_num_rows($result)>5){
  echo '<tr valign="top">
  <td colspan="4"><span class="sub">Colors</span>
  <span class="small">(click swatch to see item in that color glass)</span>';
if ($narrows==3)
{echo '<br />Click to order a <a href="pro.php?id='.$redirviewcol.'">'.$colorsetname.'</a> glass sample!</a></td></tr>';}
  else {echo'</tr>';}
  echo '<tr>';
  $cnt=0;
//next three lines check for snapshot in the string
   while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
if(substr($line['color'],0,8)!="snapshot")
{
  {
    //echo '<td><img src="' . $line['color_url'] . '" width="120" height="61" hspace="4" vspace="4"
echo '<td><img src="' . $line['color_url'] . '" hspace="4" vspace="4"
    border="0" onclick="change_glass(' . "'" . $line['color'] . "'" . ');document.mainimg.src=' . "'" . $line['url'] . "'" . '">
    </td>';
    $cnt++;
    $lookupcolor.=" if(col=='" . $line['color'] .  "'){ return '" . $line['url'] . "'; }\n";
if($cnt % $narrows == 0){
		  echo '</tr><tr>';
    }

  //next twelve lines check for snapshot in the string and do something
}
  }
}
}
mysql_free_result($result);
$query = "SELECT * from finishes where deleted=0 and pid=" . $_GET['id'] . " order by finish";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
?>
				 </table></td>
		 </tr>
		 <tr>
		   <td align="center"><?PHP
if($_GET['id']==201||$_GET['id']==202||$_GET['id']==204||$_GET['id']==205||$_GET['id']==206||$_GET['id']==207||$_GET['id']==30||$_GET['id']==31)
{echo '
<table width="255" border="0" cellspacing="0">
		   <tr valign="middle">
   <td align="center"><a href="javascript:void(viewer8.show(0))"><img src="Swatches/blackpendantthumb.png" /></a></td>
   <td align="center"><a href="javascript:void(viewer9.show(0))"><img src="Swatches/rustpendantthumb.png" /></a></td>
   <td align="center"><a href="javascript:void(viewer7.show(0))"><img src="Swatches/nickelpendantthumb.png" /></a></td>
   <td align="center"><a href="javascript:void(viewer10.show(0))"><img src="Swatches/whitependantthumb.png" /></a></td>
		   </tr>
		  <tr>
		 <td colspan="2" align="center"><a href="javascript:void(viewer17.show(0))"><img src="Pendants/BLorNIpendantsnapthumb.png" /></a></td>
    <td colspan="2" align="center"><a href="javascript:void(viewer18.show(0))"><img src="Pendants/WHorBRpendantsnapthumb.png" /></a></td>
    </tr>
    </table>';
    $ispendant = 4;}
elseif($_GET['id']==1030||$_GET['id']==1031||$_GET['id']==1032||$_GET['id']==1033)
{echo '
<table width="255" border="0" cellspacing="0">
		   <tr valign="middle">
  <td align="center"><a href="javascript:void(viewer12.show(0))"><img src="Swatches/blacktrackpendantthumb.png" /></a></td>
  <td align="center"><a href="javascript:void(viewer13.show(0))"><img src="Swatches/browntrackpendantthumb.png" /></a></td>
  <td align="center"><a href="javascript:void(viewer11.show(0))"><img src="Swatches/nickeltrackpendantthumb.png" /></a></td>
  <td align="center"><a href="javascript:void(viewer14.show(0))"><img src="Swatches/whitetrackpendantthumb.png" /></a></td>
		   </tr>
    </table>';
$ispendant=3;}
elseif(mysql_num_rows($result)>0)
{echo '<center><a href="javascript:void(viewer.show(0))">Click here to review metal color and finishes.</a></center>';}
else
{echo " ";}
} //end id!=14 ?>		  </td>
		 </tr>
   </table></td>
</tr>
<tr>
<td valign="top" align="center">
   <? if($_GET['id']!=14){ ?>
   <table width="239" border="0" cellspacing="0" cellpadding="0">
			   
<?
$narrows=5;
$iftitleshows=1;
//This is for the alternate or installed views of the product in a separate table
$query = "SELECT * from glass where deleted=0 and pid=" . $_GET['id'] . " order by color";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
if((mysql_num_rows($result)>1)){
		 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
if(substr($line['color'],0,8)=="snapshot")
{
$iftitleshows++;
if($iftitleshows==2)
{
echo '<tr valign="top">
  <td colspan="4"><span class="sub">Alternate Product Photos</span></td>';
  echo '<tr>';}
//this code runs, which means you will have one line for every thumbnail
    echo '<td><img src="' . $line['color_url'] . '" hspace="4" vspace="4"
    border="0" onclick="document.mainimg.src=' . "'" . $line['url'] . "'" . '">
    </td>';
    $lookupcolor.=" if(col=='" . $line['color'] .  "'){ return '" . $line['url'] . "'; }\n";
$iftitleshows++;
}
}
}
}
mysql_free_result($result);
$query = "SELECT * from finishes where deleted=0 and pid=" . $_GET['id'] . " order by finish";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
?>
</table></td></tr><tr><td align="center">
</td>
</tr>
</tr>
<tr>
  <td height="77" colspan="2" valign="middle" border="0">
  <br /><a href="javascript:;"> </a></span>
<b>
<!-- Product description -->
<?= $name ?></b><br /><br />
<!--<div id="notify_price"></div> --></td></td>
    <tr>
		  <td align="center" colspan="2"><form name="form1" method="post" action="promultitest.php">
		    <input type="hidden" name="action" value="add">
    <input type="hidden" name="id" value="<?= $_GET['id']; ?>">
				  <table border="0" cellspacing="10" cellpadding="0">
						 <tr>
<?
$header_number=1;
//get glass color if id not equal to 14
if($_GET['id']!=14){
  $query = "SELECT * from glass where deleted=0 and pid=" . $_GET['id'] . " order by color";
  $result = mysql_query($query) or die("Query failed : " . mysql_error());
   if(mysql_num_rows($result)>5){
    echo '<td valign=top style="height: 75"><a href="javascript:void(viewer'.$viewcol.'.show(0))" style="text-decoration:none"><img src="images/Circle' . $header_number . '.png" class="nob">&nbsp;&nbsp;&nbsp;<img src="images/GlassColor.png"></a><br /><select name="glass" onChange="document.mainimg.src=lookupcolor(document.form1.glass.value)">';
    $header_number++;

//the part of the code that changing the pictures is dependent upon and also creates the drop-down list of selections  
    while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
  

if(!(substr($line['color'],0,8)=="snapshot"))
{
		  echo '<option value="' . $line['color']  . '">' . $line['color'] .  '</option>';
}
    }
    echo '</select></td>';
  
  }
  mysql_free_result($result);
}//end id!=14
//get iron color if there are any choices available
$query = "SELECT * from finishes where deleted=0 and pid=" . $_GET['id'] . " order by finish";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
  if(mysql_num_rows($result)>0){
    echo '<td valign=top><a href="javascript:void(viewer.show(0))" style="text-decoration:none" ><img src="images/Circle' . $header_number . '.png" border="0">&nbsp;&nbsp;&nbsp;<img src="images/IronColor.png" border="0"></a><br /><select name="finishes">'; 
    $header_number++;
    while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
		  echo '<option value="' . $line['finish']  . '">' . $line['finish'] .  '</option>';
    }
    echo '</select></td>';
  }
  mysql_free_result($result);
//get iron color ??
$query = "SELECT * from stocks where deleted=0 and pid=" . $_GET['id'] . " order by stock";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
if(mysql_num_rows($result)>0){
  echo '<td valign=top><a href="javascript:void(viewer.show(0))" style="text-decoration:none" ><img src="images/Circle' . $header_number . '.png" border=0>&nbsp;&nbsp;&nbsp;<img src="images/'.$ironshape.'.png"  border=0></a><br /><select name="stocks">';		  
  $header_number++;
  while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo '<option value="' . $line['stock']  . '">' . $line['stock'] .  '</option>';
  }
  echo '</select></td>';
}
mysql_free_result($result);
//get cord color
$query = "SELECT * from cord_colors where deleted=0 and pid=" . $_GET['id'] . " order by color";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
if(mysql_num_rows($result)>0){
  echo '<td valign=top><a href="javascript:void(viewer.show(0))" style="text-decoration:none" ><img src="images/Circle' . $header_number . '.png" border=0>&nbsp;&nbsp;&nbsp;<img src="images/CordColor.png"  border=0></a><br /><select name="cord_colors">';
  $header_number++;
  while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo '<option value="' . $line['color']  . '">' . $line['color'] .  '</option>';
  }
  echo '</select></td>';
}
mysql_free_result($result);
//ceiling size
if($ceiling=='Y'){
  if($static=='N'){
    echo '<td valign=top><a href="javascript:void(viewer15.show(0))" style="text-decoration:none" ><img src="images/Circle' . $header_number . '.png" border=0>&nbsp;&nbsp;&nbsp;<img src="images/CeilingHeight.png"  border=0 class="nob"><br /></a><select name="ceiling" onchange="fixprice();">';
  }
  else{
    echo '<td valign=top><a href="javascript:void(viewer15.show(0))" style="text-decoration:none" ><img src="images/Circle' . $header_number . '.png" border=0>&nbsp;&nbsp;&nbsp;<img src="images/CeilingHeight.png"  border=0></a><br /><select name="ceiling">';
  }
  $header_number++;
  $query = "SELECT * from ceiling where deleted=0 and pid=" . $_GET['id'];
  $result = mysql_query($query) or die("Query failed : " . mysql_error());
  $ceil_cost = mysql_fetch_array($result, MYSQL_ASSOC);
  // started list at 8
  for($height=8;$height<21;$height++){
    if($static=='N'){
		  $notify_price_per_inch='$' . $price . ' per linear inch drop from ceiling<br><br>';
		  echo '<option value="' . $height . "|" . number_format($ceil_cost['h' . $height]). "|" . number_format($ceil_cost['h' . $height]) . '">' . ceil_text_format($height) . '</option>'; 
    }
    else{
		  echo '<option value="' . $height . '">' . ceil_text_format($height) . '</option>';
    }
  }
  mysql_free_result($result);
  echo '</select><br />';
}
if($price <=4){
?>
  <!-- background:#CCCCCC; was removed from the next line -->
  <div id="price" style="border:#666666 1px solid; padding:9px; color:#000000; font-weight:bold;  margin:3px; text-align:center;">
    Contact gallery for pricing.
  <!--</div>-->
<?
}
else if($ceiling=='Y' and $static=='N'){
?>
  <!-- background:#CCCCCC; was removed from the next line -->
  <div id="price" style="border:#666666 1px solid; padding:9px; color:#000000; font-weight:bold;  left-margin:90px; text-align:center;"> $  <?= number_format($price*12*8) ?></div>
  <!--<div id="retail"> <strike>$<?= number_format($retail*12*8) ?></strike></div>--></span></td>
  <?
}
else{
  ?>
  <!-- background:#CCCCCC; was removed from the next line -->
  <div id="price" style="border:#666666 1px solid; padding:9px;  color:#000000; font-weight:bold; left-margin:90px; text-align:right;"> $ <?= number_format($price) ?>
</div>
<?
if($price<$retail){
?>
  <div id="retail"> <strike>$
  <?= number_format($retail) ?></strike></div>
  <? } ?>
  </span></td>

<? }?>
</td>
<?
//get ceil cap color
$query = "SELECT * from ceil_cap where deleted=0 and pid=" . $_GET['id'] . " order by color";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
if(mysql_num_rows($result)>0){
?>
  <td width="18"></td>
<?
  echo '<td valign=top><a href="javascript:void(viewer'.$ispendant.'.show(0))" style="text-decoration:none" ><img src="images/Circle' . $header_number . '.png" border=0>&nbsp;&nbsp;&nbsp;<img src="images/CapPoleColor.png" border=0></a><br /><select
name="ceil_cap">';
  $header_number++;
  while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo '<option value="' . $line['color']  . '">' . $line['color'] .  '</option>';
  }
  echo '</select></td>';
}
mysql_free_result($result);
//get glass shape
$query = "SELECT * from glass_shapes where deleted=0 and pid=" . $_GET['id'] . " order by shape";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
if(mysql_num_rows($result)>0){
?>
  <td width="18"></td>
<?
  echo '<td valign=top><a href="javascript:void(viewer.show(0))" style="text-decoration:none" ><img src="images/Circle' . $header_number . '.png" border=0>&nbsp;&nbsp;&nbsp;<img src="images/GlassShape.png" border=0></a><br /><select
name="glass_shape">';
  $header_number++;
  while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo '<option value="' . $line['shape']  . '">' . $line['shape'] .  '</option>';
  }
  echo '</select></td>';
}
mysql_free_result($result);
//get glass shape
$query = "SELECT * from leafs where deleted=0 and pid=" . $_GET['id'] . " order by leaf";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
if(mysql_num_rows($result)>0){
?>
  <td width="18"></td>
<?
  echo '<td valign=top><a href="javascript:void(viewer2.show(0))" style="text-decoration:none" ><img src="images/Circle' . $header_number . '.png" border=0>&nbsp;&nbsp;&nbsp;<img src="images/LeafOption.png" border=0></a><br /><select
  name="leafs">';
  $header_number++;
  while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo '<option value="' . $line['leaf']  . '">' . $line['leaf'] .  '</option>';
}
echo '</select></td>';
}
mysql_free_result($result);
//select multiples of the same item
$query = "SELECT * from glass where deleted=0 and pid=" . $_GET['id'] . " order by color limit 1";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
   if((substr(($line['url']),0,9)!="/Painters")&&(substr(($line['url']),0,10)!="/Sculpture")){
//enter in code to make multiple orders a selectable option
echo '<td valign=top align=center><img src="images/Quantity.png" border=0></a><br /><select
  name="quantity">
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
  <option value="6">6</option>
  <option value="7">7</option>
  <option value="8">8</option>
  <option value="9">9</option>';
  echo '</select></td>';
}
    else {echo 'this product cannot be ordered in multiples';}
}
mysql_free_result($result);
?>
<!--</tr>
<tr>-->
<td align="left">
<?php
  if ($price >3){
  //echo '<tr>';
  echo '<td colspan="7" align="right">';
  echo  '<img src="images/addtocart.png" hspace="4"  onclick="';
  ?>
  <?php //openWindow('addcart.html','confirmation',200,200);?>
  <?php echo 'document.form1.submit();">';
  echo '</td>';
  //echo '</tr>';
}
?>
</td>									 
</tr>
</table>
</form>
</tr>
</table>
<?
if($ceiling=='Y' && $static=='N'){ ?>
<script>
//initialize the default price
fixprice();
</script>
<? } ?>
<script>
function lookupcolor(col) {
  <?= $lookupcolor ?>
}
document.getElementById('notify_price').innerHTML='<?= $notify_price_per_inch ?>' ;
</script>
<script>
//default ceiling height
if(document.form1.ceiling){
  for(i=0;i<document.form1.ceiling.length;i++){
    if(document.form1.ceiling.options[i].text == '8(18drop)'){
		  document.form1.ceiling.options[i].selected = true;
break;
    }
  }
}
</script>
<?= $description; ?>
<br />
<br />
<?= $redirect; ?>
<br />
<?=stripslashes($col_value);?>
<br />
<?=
$nostr = "";
  $showdims = substr($dims, 0, 70);
  echo $showdims;
?>									 
<br />
<br />
<?= $bulb; ?>
<!-- </div> end of centering container div> -->
<br /><br /><br /><a href="returnpolicy.html">Return Policy and Terms of Sale</a>
</body>
</html>
<?						
/* Closing connection */
mysql_close($link);
?>

  • 0

#2 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 30 April 2012 - 01:30 PM

You don't. You make one call with quantity and artno, and backend adds to basket. And normally, you don't have an item more than once in a basket, but with a higher quantity than one per row.
  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#3 Cyberen

Cyberen

    CC Regular

  • Member
  • PipPipPip
  • 41 posts

Posted 30 April 2012 - 02:02 PM

To anyone who reads this, the answer has been found.

on the first few lines, the following is added to the code:

if($_POST['action']=='add'){
  if(!isset($_SESSION['cart'])){
    $_SESSION['cart']=array();
  }
  $item=$_POST['id'] . '||';
  $item.=$_POST['glass'] . '||';
  $item.=$_POST['finishes'] . '||';
  $item.=$_POST['stocks'] . '||';
  $item.=$_POST['cord_colors'] . '||';
  $item.=$_POST['ceiling'] . '||';
  $item.=$_POST['glass_shape'] . '||';
  $item.=$_POST['leafs'] . '||';
  //$item.=$_POST['quantity'] . '||';
  $item.=$_POST['ceil_cap'];
  $quantity =$_POST['quantity'];
  if ($quantity == 0)
  {$quantity = 1;}
  $test=0;
  while ($test < $quantity)
  {
  array_push($_SESSION['cart'],$item);
  $test ++;
  }
See right there on the bottom?
Quantity is added as post data with a conditional statement which pushes the array as many times as the quantity demands.
Takes care of the job just fine!
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download