nepoverljiv Posted December 19, 2012 Share Posted December 19, 2012 I have one code which I use to add articles in shopping cart. In another website working without any kind of problem, but on new one he makes me problem, he add me double article in shopping cart. I press once “add to basket” but he put me twice that articles. When I press “add to basket” I calling this code to found out which articles is: <?php session_start(); $var=$_SERVER['REQUEST_URI']; //reading $id = substr(strrchr($var, "korpa?"),6 );//reading first element after "?" $tbl_name="description"; //table name $_SESSION['korpa']+=$row[price]; if($_SESSION['numproduct']==0){ $_SESSION['articles']=array($id); $_SESSION[numproduct]++; }else{ array_push($_SESSION['articles'],$id); $_SESSION[numproduct]++; } redirect("javascript: history.go(-1)"); ?> On main page I using this code to see what exist in shopping cart: $i=0; $tbl_name="description"; $query = count($_SESSION['articles']); if($query==0){ echo "Your shopping cart is empty."; }else{ echo "In your shopping cart exist:<br/><br/>"; for($i=0;$i<=$query-1;$i++){ $br=$i+1; connect(); $element=$_SESSION['articles'][$i]; $sql="SELECT * FROM $tbl_name WHERE id=$element"; $subject_set=mysql_query($sql); $subject=mysql_fetch_array($subject_set); echo " ".$br.". "; echo $subject['name']; echo " - <b>".$subject['prices']." USD</b><br/> "; } echo "<p align=right><a href=index.php?=order class=basket>Order</a> · <a href=includes/delete.php>Delete items</a></p>"; Does anyone knows why articles goes twice in shopping cart? Quote Link to comment https://forums.phpfreaks.com/topic/272200-php-session-shopping-cart-problem/ Share on other sites More sharing options...
nepoverljiv Posted December 22, 2012 Author Share Posted December 22, 2012 I have figured it out that problem is in this line of code: $sql="SELECT * FROM $tbl_name WHERE id=$element"; $subject_set=mysql_query($sql); $subject=mysql_fetch_array($subject_set); Everything before is ok, but here give me double values. Please help me Quote Link to comment https://forums.phpfreaks.com/topic/272200-php-session-shopping-cart-problem/#findComment-1400865 Share on other sites More sharing options...
Christian F. Posted December 22, 2012 Share Posted December 22, 2012 What do you mean with "double values"? Show us an example of what you expect to get, and what you are getting. Also have you read the PHP manual page for mysql_fetch_array ()? Quote Link to comment https://forums.phpfreaks.com/topic/272200-php-session-shopping-cart-problem/#findComment-1400887 Share on other sites More sharing options...
nepoverljiv Posted December 22, 2012 Author Share Posted December 22, 2012 (edited) I wanna get in my shopping cart this: 1.Name of first articles - Price of first articles After I add one more wanna get this: 1.Name of first articles - Price of first articles 2.Name of second articles - Price of second articles But instead that I get this: 1.Name of first articles - Price of first articles 2.Name of first articles - Price of first articles After I add one more wanna get this: 1.Name of first articles - Price of first articles 2.Name of first articles - Price of first articles 3.Name of second articles - Price of second articles 4.Name of second articles - Price of second articles I am using exactly same code on another website and there working ok, I can't figured it out why happen this on new one sites. Edited December 22, 2012 by nepoverljiv Quote Link to comment https://forums.phpfreaks.com/topic/272200-php-session-shopping-cart-problem/#findComment-1400895 Share on other sites More sharing options...
nepoverljiv Posted December 22, 2012 Author Share Posted December 22, 2012 U can see online www.vuna.034.rs. On right side you can see "U korpu" (add to cart) , and you will see what will happen Quote Link to comment https://forums.phpfreaks.com/topic/272200-php-session-shopping-cart-problem/#findComment-1400897 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.