Jump to content

shopping cart problem


dazz_club

Recommended Posts

Hi guysive got this shopping cart on my website that seems to be causing me a headache.If i was to be a customer and add some products to my cart and then contiue to shop. All is well. But if i was to carry on shopping and then decide to look at what products i have. When i click on the link to view cart, its empty.whats the problem?cheers

Link to comment
Share on other sites

Yes, post the code and link so we can search for a problem. You need to be using a database or file to do this.. do you know what type of database your using? (Or if it is a file)

Link to comment
Share on other sites

aw man, i thought you gave up on me, but my mistake.heres the php code for "showcartinclude.php" which appears on showcart.php

<?phpinclude("inc/openconn.php");?><script language="javascript">function checkqty()	{	  		var ch=0;		len = document.frmcart.elements.length;		var i=0;		for( i=0; i<len; i++) 		{			  if (document.frmcart.elements[i].name=='txtqty[]') 				{					if (isNaN(document.frmcart.elements[i].value))						{							ch = 1;												}				}		}				if (ch == 1)		{			alert("Invalid Quantity ..");				return false;		}		else		{			document.frmcart.action="updatecart.php";			document.frmcart.submit();				}	}function onlyNumerics(i1){		code = event.keyCode	if((code >=48) && (code <=57) || (code ==13)) //0 - 48 and 9 - 57	{		if(code ==13)				lostfocus(i1.value,j1,k1,m1);				} 	else if (code==47)		  event.returnValue = true	else		  event.returnValue = false}</script><link type="text/css" rel="stylesheet" href="common/design.css"><table width="100%"  border="0" cellpadding="0" align="left"><form name="frmcart" action="shippinginformation.php?userid=<?=$userid?>" method="post"> <!-- <form name="frmcart" action="shippinginformation.php?userid=<?=$userid?>" method="post">--><input type="hidden" name="userid" value="<?=$userid?>"><?	$sqlt="select * from ordertemp where memberid='" . $_GET['memberid'] . "'";	$rest=mysql_query($sqlt) or die(mysql_error());	while($rowt=mysql_fetch_array($rest))	{?><input type="hidden" name="ordertempid[]" value="<?=$rowt['ordertempid'];?>"><?	}?>  <tr>	  <td class="text"><font color="#330099">Instructions:</font><br>	  <p class="text">	  To update quantity, please change the quantity and press 'Update cart' button. <br>	To remove a product, please set the quantity to '0' and press 'Update cart' button.	</font></td>  </tr>  <tr>	<td>	<table width="100%"  border="0" cellpadding="0" cellspacing="0">	  <tr bgcolor="#CCCCCC">		<td colspan="5" bgcolor="#999999">		<font face="Verdana" style="font-size: 10pt" color="#330099"><b>		<p>Cart Items</p>		</b></font>		</td>		</tr>	  <tr bgcolor="#CCCCCC">		<td width="30%" align="left" bgcolor="#CCCCCC">			<font face="Verdana" style="font-size: 8pt" color="#330099"><b>Products</b></font>		</td>		<td align="center" width="25%">			<font face="Verdana" style="font-size: 8pt" color="#330099"><b>Plate Size</b></font>		</td>		<td width="25%" align="center">			<font face="Verdana" style="font-size: 8pt" color="#330099"><b>Price</b></font>		</td>		<td align="center">			<font face="Verdana" style="font-size: 8pt" color="#330099"><b>Quantity</b></font>		</td>		<td align="center">			<font face="Verdana" style="font-size: 8pt" color="#330099"><b>Total Price</b></font>		</td>	  </tr>	  <?		  $sqlc="select * from cart where memberid='" . $_GET['memberid'] . "'";		$resc=mysql_query($sqlc) or die(mysql_error());		$cnt=1;		$subtotal=0;		$resno=mysql_num_rows($resc);		if($resno==0)		{	?>	<tr>		<td height="16" colspan="5" align="center" class="bodyfont"><b>There are no any Product to Display</b></td>		</tr>	  <tr>	<?		}		else		{		while($rowc=mysql_fetch_array($resc))		{	  ?>	  		<td class="text">		<?			if($rowc['status']=='FL')			{				echo $rowc['productname'];			}			else			{				echo "Plate Reg. No.".$rowc['productname'];			}		?> </td>		<td align="center" class="text"><?=$rowc['platesize'];?></td>		<td align="center" class="text">£<?=$rowc['price'];?></td><input type="hidden" name="cartid[]" value="<?=$rowc['cartid'];?>">		<input type="hidden" name="price[]" value="<?=$rowc['price'];?>">		<td align="center" class="text"><input type="text" class="text" name="txtqty[]" size="4" value="<?=$rowc['quantity'];?>" class="inputbox1"></td>		<td align="center" class="text">£<?=$rowc['total'];?></td>	  </tr>	  <tr>		<td class="text"><p style="margin-left:81"><?=$rowc['productname1'];?></p></td>		<td align="center" class="text"><?=$rowc['platesize1'];?></td>		<td align="center" class="text"> </td>		<td align="center"> </td>		<td align="center" class="text"> </td>	  </tr>	  <?		  $subtotal=$subtotal+$rowc['total'];		$cnt++;		}//end while cart	  ?>	  <tr>		<td> </td>		<td> </td>		<td> </td>		<td align="right"  class="text"><font color="#330099"><P>Sub Total= </P></font> </td>		<td align="center" class="text"><font color="#330099"><P><b>£<?=$subtotal?></b></P></FONT></td>	  </tr>	  <?		  }//end if	  ?>	  <tr bgcolor="#CCCCCC">		<td> </td>		<td> </td>		<td> </td>		<td align="center"> </td>		<td > </td>	  </tr>	  <tr>		<td><a href="index.php"><font face="Verdana" style="font-size: 8pt">Continue Shopping</font></a></td>		<td> </td>		<td> </td>			<td align="center"> 			  <?		if($resno!=0)		{		?>			  <input name="button2" type="submit" class="inputbox" value="UPDATE CART" align="left" onclick="java script:checkqty(); return false;">			  <?		}		?>			</td>			<td> 			  <?		if($resno!=0)		{		?>			  <input name="button" type="submit" class="inputbox" value="CHECK OUT" align="right"> 			  <?		}		?>			</td>	  </tr>	</table>	</td>  </tr>  <tr>	  <td> <div align="right"> </div></td>  </tr>  </form></table>

cheers

Link to comment
Share on other sites

There is no 'memberid' generated when you click on the "SHOPPING CART" menu button.You made the scripts? If not, you should see how the 'memberid' is generated on the submitcart.php page, then do that on every page where the "SHOPPING CART" appears and put it in the href for the button (like showcart.php?memberid=...). It looks like a session id.

Link to comment
Share on other sites

Hi there thanks for your quick reply?ive tried looking at the coding for "submitcart.php" for code that generates the memeber id and i cant find it.heres the code if it helps to point it out.

<?session_start();include("inc/openconn.php");foreach($_GET as $getvar => $getval){ ${$getvar} = $getval; } foreach($_POST as $postvar => $postval){ ${$postvar} = $postval; }  error_reporting(1);$memberid=session_id();$platetype = $_GET['platetype'];$platecost = $_POST['platecost'];$platprice = $_POST['plateprice'];$regno = $_POST['regno'];$frontpsize = $_POST['frontpsize'];$rearpsize = $_POST['rearpsize'];$ptype = $_POST['ptype'];$fonts = $_POST['fonts'];$sideimage_id = $_POST['sideimage_id'];$sideimageback_id = $_POST['sideimageback_id'];$rightsideimage_id = $_POST['rightsideimage_id'];$rightsideimageback_id = $_POST['rightsideimageback_id'];$customsideimg = $_POST['sideimage_url'];$platebg = $_POST['platebg'];$border = $_POST['border'];$slogan = $_POST['slogan'];$slogancolour = $_POST['slogancolour'];$frontsurr = $_POST['ddlsf'];$rearsurr = $_POST['ddlsr'];if($platetype=='s'){$tp=$platecost * 1;$sql="insert into cart (memberid,productname,platesize,price,quantity,total,orderdate,platetype) 	values ('$memberid','$regno','Standard','$platecost','1','$tp',NOW(),'$ptype')";$res=mysql_query($sql) or die(mysql_error());//$row=mysql_fetch_array($res);$sqlot="insert into ordertemp ( memberid, regno, platesize1, platesize2, fontid, sidebadgeid, sidebadgesrc, sidebadgeback, rightsidebadgeid, rightsidebadgeback, backgroundid, bordername,bottomtext,btc, frontsurround, rearsurround, price,status,platetype) values		('$memberid','$regno','$frontpsize', '$rearpsize', '$fonts', '$sideimage_id','$customsideimg','$sideimageback_id', '$rightsideimage_id', '$rightsideimageback_id' ,'$platebg','$border','$slogan','$slogancolour', '$frontsurr','$rearsurr' ,'$tp','CP','$ptype')";$resot=mysql_query($sqlot) or die(mysql_error());}//end if standardif($platetype=='r'){$tp=$platecost * 1;$sql="insert into cart (memberid,productname,productname1,platesize,platesize1,price,quantity,total,orderdate) 	values ('$memberid','$regno1','$regno2','$platesize1','$platesize2','$platecost','1','$tp',NOW())";$res=mysql_query($sql) or die("cart error".mysql_error());$row=mysql_fetch_array($res);$sqlot="insert into ordertemp (memberid,regno,regno1,platesize1,platesize2,fontid,bordername,bottomtext,btc,price,status) values		('$memberid','$regno1','$regno2','$platesize1','$platesize2','$fonts','$border','$slogan','$slogancolour','$tp','R')";$resot=mysql_query($sqlot) or die("ordertemp error".mysql_error());}//end if standardif($platetype=='m'){$tp=$platprice * 1;$sql="insert into cart (memberid,productname,productname1,platesize,platesize1,price,quantity,total,orderdate) 	values ('$memberid','$regno1','$regno2','$platesize1','$platesize2','$platprice','1','$tp',NOW())";$res=mysql_query($sql) or die("cart error".mysql_error());$row=mysql_fetch_array($res);$sqlot="insert into ordertemp (memberid,regno,regno1,platesize1,platesize2,fontid,bordername,bottomtext,btc,price,status) values		('$memberid','$regno1','$regno2','$platesize1','$platesize2','$fonts','$border','$slogan','$slogancolour','$tp','M')";$resot=mysql_query($sqlot) or die("ordertemp error".mysql_error());}//end if standardif($platetype=='p'){	$sqlp="select * from product where productid='$productid'";	$resp=mysql_query($sqlp) or die(mysql_error());	$rowp=mysql_fetch_array($resp);	//$tp=$platecost * 1;$sql="insert into cart (memberid,productname,price,quantity,total,orderdate,status) 	values ('$memberid','".$rowp['productname']."','".$rowp['productprice']."','1','".$rowp['productprice']."',NOW(),'FL')";$res=mysql_query($sql) or die("cart error".mysql_error());$row=mysql_fetch_array($res);$sqlot="insert into ordertemp (memberid,regno,price,status,productid) values		('$memberid','".$rowp['productname']."','".$rowp['productprice']."','P','$productid')";$resot=mysql_query($sqlot) or die("ordertemp error".mysql_error());}//end if standard//$userid="$userid";if($platetype=='b'){$tp=$platecost * 1;$sql="insert into cart (memberid,productname,platesize,price,quantity,total,orderdate,platetype) 	values ('$memberid','$regno','Standard','$platecost','1','$tp',NOW(),'$ptype')";$res=mysql_query($sql) or die(mysql_error());$row=mysql_fetch_array($res);$sqlot="insert into ordertemp (memberid,regno,fontid,sidebadgeid,backgroundid,bordername,bottomtext,btc,price,status,platetype) values		('$memberid','$regno','$fonts','$sideimage_id','$platebg','$border','$slogan','$slogancolour','$tp','B','$ptype')";$resot=mysql_query($sqlot) or die(mysql_error());}//end if blackplate?><script language="JavaScript">	document.location.replace("showcart.php?memberid=<?=$memberid?>");</script>

cheers

Link to comment
Share on other sites

So, on all pages where the button appears, there must besession_start();and then$memberid=session_id();(you can't use session_id() without session_start before it).And in the link you type:<a href="showcart.php?memberid=<?php echo $memberid; ?>" ...>

Link to comment
Share on other sites

Hi again,I dont know if you had the chance to create your own number plate, but ive noticed when i use all the drop down menus to create a number plate the price becomes something like £34.0000000009.is that my database doin that at all?cheers

Link to comment
Share on other sites

I'm not sure what a number plate is, but you can round that value. Errors like that are typically the result of floating-point rounding. Since most fractions are infinite, and computer numbers are finite, you get small errors like that.You can either use round:$val = round($val, 2); // round to 2 decimal placesor use ceil or floor to round up or down:$val = ceil($val); // round up$val = floor($val); // round down

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...