Error 1064 in php call to mysql

06-21-08, 10:45 PM
|
|
Newbie Coder
|
|
Join Date: Jun 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The error is gone now, whew! And I changed the quantity back to 1 (adjusted for test purposes, as cause-and-effect is my main mode of learning). I'll view the code line by line to see what changes you made. But all is not well...
The cart only shows one valid item, and carries artifacts of other items with no description, no price. The first item I select is there until I select the second item, then it disappears and the second item appears. Then the second item remains and other blank item lines appear.
I think this code is possessed...
Thank you, I am learning.
|

06-21-08, 11:04 PM
|
 |
-
|
|
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
|
|
If you are at a point where you feel really stuck, try the following:
Put echo commands in until you find the line that is failing. This is the brute force, last resort approach to identify the problem.
I'm assuming this code is part of something that includes a session_start.
Last note - do / while can be a risky approach. I prefer to use
var_dump is a great debugging aid.
Good luck. If it is any consolation, you will solve this, and you will never forget what you learned. 
|

06-21-08, 11:15 PM
|
|
Newbie Coder
|
|
Join Date: Jun 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I'm getting quite good at sticking echo commands in the right places. But I don't have enough experience yet to use that info to get a solution. Since I am doing these exercises not for classwork but for my own personal enlightenment, I find it mildly amusing that I can't let it go and say oh well. No one is grading me but me, and I am stubbornly insistent on making it work.
I believe the code is now failing in
Remove Item Product Quantity Price Each
Remove 1 $0.00 // first item added to cart disappears when second is added
Remove Jamaican Blue Mountain Coffee 1 $22.95 // second item is fine
Remove 1 $0.00 // subsequent items are blank and don't affect previous items
Empty Cart Your shopping cart contains 3 product(s). Total: $22.95
Last edited by Vikki; 06-21-08 at 11:18 PM.
|

06-21-08, 11:15 PM
|
 |
Community Liaison
|
|
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
|
|
I am not sure what you did, but it works perfectly on my machine.
I tested it in both FireFox and IE.
This is the code I used.
ShoppingCart.php
ShowCart.php
But then of course I am not using your style sheet. Because you didn't provide it.
__________________
Jerry Broughton
Last edited by job0107; 06-21-08 at 11:33 PM.
|

06-21-08, 11:37 PM
|
|
Newbie Coder
|
|
Join Date: Jun 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The style sheet is just font size and color. It's irrelevant for debugging.
I think I will make a new folder and put the files in and try it again. Hearing that it works is very encouraging!
|

06-22-08, 12:10 AM
|
|
Newbie Coder
|
|
Join Date: Jun 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
It's better...but not yet there.
I copied the code from the first section above, which is GosselinGourmetCoffees.php, and copied and modified it for G-G-Olives.php and G-G-Spices.php. All that changes is the page header and table name.
When I run the program the first table selected works PERFECTLY. If I try to add items from one of the other tables, they come up blank in the shopping cart.
Last edited by Vikki; 06-22-08 at 12:21 AM.
|

06-22-08, 01:26 PM
|
 |
-
|
|
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
|
|
Check the table names (in the variables) and the (construction of the) select statements. Test the other tables in MySQL directly.
|

06-22-08, 02:22 PM
|
|
Newbie Coder
|
|
Join Date: Jun 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
There are three tables: coffee, olives, spices.
No matter which table I first select from, it works. When I select items from the second table, it wipes the items from the other table from the cart. Once it does that, I cannot select items from the third table. It does not matter in which order I access the tables.
The initial mysql query works in mysql monitor. The subsequently generated queries are missing the table name and product ID, which should be provided by the addItem function. It's either failing in addItem, or in getProductList. But I'm too green at this to trace it down, though I am trying.
|

06-22-08, 11:52 PM
|
 |
-
|
|
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
|
|
Quote:
|
When I select items from the second table
|
Sounds like a session issue or a class conflict.
You might want to pass the table into the class upon instantiation.
|

06-24-08, 09:07 AM
|
 |
Community Liaison
|
|
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
|
|
Ok Vikki, I have been tossing this around for a while and have finally come up with a solution for you.
Instead of storing your items in a simple array, I used a multi-dimensional array to store the item ID and table name. These values are used to lookup the items.
The multi-dimensional array is constructed as rows with two columns ( itemID & Table name ($Orders[row][column]) ).
I took your links and put them in a separate file. You need to put your table names in there. Where table=table name.
The default table name is stored in GosselinGourmetGoods.php under:
So here is the code in four files:
GosselinGourmetGoods.php
ShoppingCart.php
ShowCart.php
links.html
In links.html replace users, users1 and users2 with your table names.
When you remove items from the Cart or empty the Cart, it doesn't unset that array element it just NULLs the elements for that item.
So when you fetch the items from the Orders array, you neeh to fetch only the elements that have value.
The Orders array will look like this:
Product ID: $Orders[row][0]
Table name: $Orders[row][1]
The only thing this program doesn't do yet is allow you to adjust the quantity from the program.
__________________
Jerry Broughton
Last edited by job0107; 06-24-08 at 09:13 AM.
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|