473,231 Members | 2,006 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

Not passing correct value into shopping cart (wish list)

Hi all, New to posting on this forum and trying to get my add page to wish list working correctly.

Passing the code and type variables through to this page and echos fine. But when trying to add my database results into an array I am getting the Resource id #4. The code I am using is below without the dasebase password.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include 'session.php';
  3. $con = mysql_connect("94.136.61.138", "xxxxx", "xxxx");
  4. setcookie ('basket', $cart);
  5.  
  6. if (isset ($_POST["code"])) $code = mysql_real_escape_string($_POST["code"]);
  7. if (isset ($_POST["type"])) $type = mysql_real_escape_string($_POST["type"]);
  8.  
  9. $dbcode = $_POST["code"];
  10. $dbtable = $_POST["type"];
  11. echo "table =" .$dbtable;
  12. echo "<br>";
  13. echo "code = ".$dbcode;
  14.  
  15.     $query = mysql_db_query("xxxxxxx", "select smalltitle, smallimage, alt_small_img, costprice from $dbtable where pagelocation = '$dbcode'");
  16.     echo mysql_error();
  17.     while ($row = mysql_fetch_row($query)){
  18.     echo $row[0];
  19.  
  20.         for ($z=0; $z<count($code); $z++){
  21.             $shoppinglist[] = array(($code[$z][1] /$row[1]) ,$row[0], $row[1], 0);
  22.  
  23.         }
  24.  
  25. }
  26. for ($i=0; $i<count($shoppinglist); $i++){
  27.     addel($shoppinglist[$i][0], $shoppinglist[$i][1], $shoppinglist[$i][2], $shoppinglist[$i][3]);
  28. }
  29.  
  30. echo $query;
  31. //echo $shoppinglist;
  32.  
  33.  
  34.  
  35. //header("location:wish_list.php"); 
  36. ?>
--------

Any help with this would be great.

To see the results of this you can look at the page

LINK REMOVED FOR USER SAFETY.

Many thanks and hope this is easy to sort as I have try changing lots of things, but always come out with this error or before an Array error.

Thanks

whiskyman
Feb 13 '10 #1
5 1952
Atli
5,058 Expert 4TB
Hey.

The echo on line #30 is generating the "Resource id #" output. It is what you get when you echo the return values of functions that return resources, rather than actual variables. - These include functions like mysql_connect and mysql_query.

Those return values are not meant to be used directly, but to be used by other functions to fetch values from external resources.

P.S.
You should avoid using the mysql_db_query function. Using the mysql_select_db and mysql_query separately is recommended instead. (The mysql_db_query function is deprecated in 5.3, and removed in 6.0)
Feb 13 '10 #2
Hi Atli and thank you for your message back.

I have changed that code and taken away the echos. I now get the cart going right through to the next page and displays the value Array now. you can see this by clicking the link below again. Nothing appears in the cart. Im sure my session.php code is correct, but I have listed it below and added the include session.php code to every page.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.       session_start(); 
  3.     session_name('cartdetails');
  4.     $private_id = session_id();
  5.     $privateKey = $_SESSION['pr_key'];
  6.     $IPADDRESS = $_SERVER['REMOTE_ADDR']; 
  7.  
  8.  
  9.     if (!isset($_SESSION["cart"])){
  10.         $_SESSION["cart"] = array();
  11.         $_SESSION["partof"] = 0;
  12.     }
  13.  
  14.     function wishlist($type, $code){
  15.         $tmp = $_SESSION["cart"];
  16.         $is = false;        
  17.         for ($i=0; $i<count($tmp); $i++){
  18.             if (($tmp[$i][1] == $code)){
  19.                 $is = true;
  20.                 $tmp[$i][0] = $tmp[$i][0] + $no;
  21.                 break;
  22.             }
  23.         }
  24.         if ($is==false){
  25.             $tmp[] = array($type, $code);
  26.         }
  27.         $_SESSION["cart"] = $tmp;
  28.     }
  29.  
  30. ?>
Any other help you have on this would be excellent.
Feb 14 '10 #3
Markus
6,050 Expert 4TB
Hey, Whiskeyman. Welcome to Bytes.com.

Firstly, in future could you, when posting code, wrap the code in [code] ... [/code] tags. This formats the code making it easier to read and, thus, debug.

Second, to your problem. The reason you see "Array" when trying to output the session data is because you need to access specific indexes of the array, just like you would any other array. As you are not using strings for your indexes, you'll access them numerically (in this case 0 for $type and 1 for $code).

Expand|Select|Wrap|Line Numbers
  1. printf('Type is: %s<br />Code is: %s', $_SESSION['cart'][0], $_SESSION['cart'][1]);
  2.  
Marl/
Feb 14 '10 #4
Hi Markus and thanks for your help there. I am still struggling to get this working. We keep changing things and hopefully I will get there. Thanks again and any other suggestings would be great. It really the first time I have done a session cookie and just getting my head round it.

Thanks again and I will make sure next time I put code into this forum I will put the tags in.

Alan
Feb 14 '10 #5
numberwhun
3,509 Expert Mod 2GB
Hello! I removed your link from your thread, but not for spam purposes. The reason is because if you go to the link, it seems that the site is questionable in the browsers I tried it in. This could be caused by the SSL cert being bad or that the site is an IP but resolves to a .ru URL.

Either way, please make sure the that links you post are safe and resolve correctly. Thank you!

Regards,

Jeff
Feb 14 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Newbie | last post by:
OK, this may be impossible since I'm using 3rd party shopping cart ASP software, but I've been able to finagle a lot of other stuff I thought wouldn't work, so here we go: I'm using a form in...
2
by: Don Grover | last post by:
I am retrieving costs and product id's from a sql db. and need to build a shopping cart around it. How do I store the selected items and qty req so I can move into another catalog and total up as...
1
by: Jia Sun | last post by:
hello , everybody , i need a similar program , just like fancyimport.com if possible, pls contact me ,thank you very much . inchina@gmail.com
9
by: Penny | last post by:
Hi all, I've built an online shopping cart using ASP Classic(based on a 'WebThang' tutorial). The shop cart page (with table showing customers selected items and costs) has only 3 buttons/links....
1
by: MickG | last post by:
I am trying to change the value of the variable "hard" according to which radio button is pressed and I am having no joy. Could anyone help me with this, the problematic section is marked with...
2
by: G.E.M.P | last post by:
High Level Session Handling Design for a Shopping cart 0) What am I missing? 1) How does OSCommerce do it? I'm thinking about building a shopping cart from scratch, using a library of dynamic...
1
by: Vahehoo | last post by:
Hi, I have an ASP .Net e-business site that is built using DNN 2.0. I am having troubles passing my shopping cart items to PayPal. I implemented a total paynow button, but it was not good enough...
1
by: Travis1012 | last post by:
Hi, I require a shopping cart which gathers infomation from customers on what they wish to purchase (all products show a price with them). After they have created their list, they go to the cart...
1
by: Travis1012 | last post by:
Hi, I require a shopping cart which gathers infomation from customers on what they wish to purchase (all products show a price with them). After they have created their list, they go to the cart...
1
by: Harlan Messinger | last post by:
The Doctor wrote: A quandary? Hardly. I would think that you'd address this question to the bank whose page you are submitting the information to.
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.