Error 1064 in php call to mysql

06-21-08, 03:00 AM
|
|
Newbie Coder
|
|
Join Date: Jun 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
Error 1064 in php call to mysql
Hello. My first post...
I am working on the same homework project Spherion posted in May. I have gone over my code several times and it is all correct "by the book", but it doesn't work properly. I've found a few other copies on the web that have the same issue. Here's one example:
http://www.adamtest.net/ch11/GosselinGourmetGoods.php
If you select the first item, it adds to the cart without issue. But when you add an item, the error 1064 shows up. The line number depends on the line breaks in the $SQLstring definition, mine is called on line 2.
I've spent two days trying to find the issue, but as a brand new PHP programmer, I am not having any luck. The problem seems to be in the public function showCart area of the script. However, the SQLstring echo that I currently have commented out returns a perfectly formed sql query, so I don't understand why I am receiving a syntax errror. SQL query and result below:
Here is the code to ShoppingCart.php:
And the code that calls it:
and ShowCart.php
Any help is greatly appreciated.
Last edited by Nico; 06-21-08 at 03:16 AM.
Reason: Please use [php] wrappers when posting PHP code.
|

06-21-08, 08:16 AM
|
 |
Level II Curmudgeon
|
|
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
|
|
As I understand it, the error 1064 occurs due to a mismatch between reserved keywords and the mySQL version used- different versions have different reserved words. If used by a non-supported version it causes the 1064 error to be thrown.
|

06-21-08, 08:32 AM
|
 |
-
|
|
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
|
|
You might want to add backticks and braces, like so:
The backticks should prevent issues if there are spaces in the OrderTable data, and the braces will evaluate what is inside them.
|

06-21-08, 12:08 PM
|
|
Newbie Coder
|
|
Join Date: Jun 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
mysql 1064
Thank you for the suggestions. Implementing those changes malformed the mySQL string so that no database was selected.
By adding echo points, I believe I have narrowed the error down to the code included in this function:
The reason I suspect this code is that the error message returns a malformed SQLstring with no table or productID included.
SELECT * FROM spices WHERE productID='SPICE003' // from my echo line in function showCart
Remove Lovage Root 1 $4.39 // table content generated
SELECT * FROM WHERE productID='' // generated when program runs from getProductList
Unable to perform the query.
Error code 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE productID=''' at line 1
I've done a little more experimentation. now provides a valid table selection, and the first item works fine. The SECOND item selected fails. So I am now suspecting the "do" loop...please help!
Last edited by Vikki; 06-21-08 at 12:18 PM.
|

06-21-08, 02:22 PM
|
 |
-
|
|
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
|
|
Quote:
|
Error code 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE productID=''' at line 1
|
indicates a MySQL problem, which may be caused by its construction with PHP.
Echo the SQL statements, then paste them into MySQL and adjust them until they work. Then, change your code accordingly.
|

06-21-08, 02:44 PM
|
|
Newbie Coder
|
|
Join Date: Jun 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The SQL statements work in the first iteration of the loop, and in the mySQL monitor as captured in the first loop. Subsequent iterations break. I cannot find what is breaking the second iteration. It's either in the "foreach" or "do" loops, but I can't see it.
Successful first iteration
Failed second iteration.
I noticed on copying the output source that the </html> tag is missing on the output of the second iteration.
Okay...by echoing and commenting more script with
in the foreach loop, I now have:
`coffee`
SELECT * FROM coffee WHERE productID=`COFFEE002`
Unable to perform the query.
Error code 1054: Unknown column 'COFFEE002' in 'where clause'
It looks like the code is not building the OrderTable properly. This is with backticks.
I've only been working with PHP for a month, self study, so I have nowhere else to turn.
Last edited by Vikki; 06-21-08 at 03:04 PM.
|

06-21-08, 02:57 PM
|
 |
-
|
|
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
|
|
The do loop assumes the query returns some results, but if there are no results to return, it will execute the first iteration anyway.
Check this page: http://www.php.net/manual/en/mysqli.multi-query.php and this pagehttp://www.php.net/manual/en/mysqli.use-result.php for ideas on coding the loops.
|

06-21-08, 03:07 PM
|
|
Newbie Coder
|
|
Join Date: Jun 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
`coffee`
SELECT * FROM `coffee` WHERE `productID`='COFFEE004'
Remove Pure Kona Coffee 1 $21.45
First iteration.
``
SELECT * FROM `` WHERE `productID`=''
Unable to perform the query.
Error code 1103: Incorrect table name ''
Displayed on second iteration.
Thanks, I will look. I am STUCK...this is right out of the text, and this is my third day trying to make it work as the screenshots show.
Last edited by Vikki; 06-21-08 at 03:19 PM.
|

06-21-08, 04:13 PM
|
|
Newbie Coder
|
|
Join Date: Jun 2008
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The failure is at the function addItem(). It is not retrieving $this->Orders[$ProdID] = 1; or
$this->OrderTable[$ProdID] = $this->TableName;
The data is in the table. I can select any item succesfully as the first item in the empty cart.
Can anyone help?
Called from
Last edited by Vikki; 06-21-08 at 04:27 PM.
|

06-21-08, 10:27 PM
|
 |
Community Liaison
|
|
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
|
|
Try your class like this. I think you will be pleasantly pleased.
ShoppingCart.php
__________________
Jerry Broughton
Last edited by job0107; 06-21-08 at 10:55 PM.
|
|
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
|
|
|
|