Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-29-2010, 05:20 PM   PM User | #1
mOrloff
Regular Coder

 
mOrloff's Avatar
 
Join Date: Nov 2008
Location: The Great Pacific NW, USA
Posts: 421
Thanks: 8
Thanked 6 Times in 6 Posts
mOrloff is an unknown quantity at this point
Help needed discerning this error

I have a script which is throwing an error, and I'm not making much sense of it.
Error:
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 '6'' at line 2

Since this error in no way reflects what is at line two of my PHP script, I'm not sure where to look.
I did look at the SQL within the script, and other than the connection stuff (which has nothing resmbling the error), the first MySQL string is an INSERT statement broken over 2 lines.
I echoed it out, and I'm not seeing a match to the error.

Am I on the right/wrong track ??

~ Mo

Last edited by mOrloff; 03-31-2010 at 03:58 PM..
mOrloff is offline   Reply With Quote
Old 03-29-2010, 05:47 PM   PM User | #2
tomws
Senior Coder

 
tomws's Avatar
 
Join Date: Nov 2007
Location: Arkansas
Posts: 2,644
Thanks: 29
Thanked 330 Times in 326 Posts
tomws will become famous soon enoughtomws will become famous soon enough
Quote:
Originally Posted by mOrloff View Post
I echoed it out, and I'm not seeing a match to the error.
But you didn't paste it here?
__________________
Are you a Help Vampire?
tomws is offline   Reply With Quote
Old 03-29-2010, 05:51 PM   PM User | #3
mOrloff
Regular Coder

 
mOrloff's Avatar
 
Join Date: Nov 2008
Location: The Great Pacific NW, USA
Posts: 421
Thanks: 8
Thanked 6 Times in 6 Posts
mOrloff is an unknown quantity at this point

Here's a snip of the echo (which goes on for several hundred thousand rows).

0) INSERT INTO `temp` (`partnumber` ,`description` ,`condition` ,`category` ,`qty` ,`brand`,`uniqueid` ,`price`) VALUES ('Part Number','Description','Condition','Category','Quantity','Mfg','UniqueID','Price')
1) INSERT INTO `temp` (`partnumber` ,`description` ,`condition` ,`category` ,`qty` ,`brand`,`uniqueid` ,`price`) VALUES (' F02A250V4A',' F02A250V4A','','','0','','5b2cc04434ce4622b008032a985f0328','0')
2) INSERT INTO `temp` (`partnumber` ,`description` ,`condition` ,`category` ,`qty` ,`brand`,`uniqueid` ,`price`) VALUES (' FHL18G2-2',' FHL18G2-2','','','0','','e83a5c0b236a4a7a8f843109b377a59a','0')
3) INSERT INTO `temp` (`partnumber` ,`description` ,`condition` ,`category` ,`qty` ,`brand`,`uniqueid` ,`price`) VALUES (' FHL18G2-9',' FHL18G2-9','','','0','','75f07713e4d743aeb1fb31e13fe553d7','0')
mOrloff is offline   Reply With Quote
Old 03-29-2010, 05:54 PM   PM User | #4
tomws
Senior Coder

 
tomws's Avatar
 
Join Date: Nov 2007
Location: Arkansas
Posts: 2,644
Thanks: 29
Thanked 330 Times in 326 Posts
tomws will become famous soon enoughtomws will become famous soon enough
There's no 6' in that section. Check the others that you didn't paste. You may have picked up a stray apostrophe. It's a simple mysql syntax error, so one of the queries is flawed.

By the way, did you know you can insert multiple rows with one INSERT statement? Then you end up using far fewer queries than this.
__________________
Are you a Help Vampire?
tomws is offline   Reply With Quote
Old 03-29-2010, 06:19 PM   PM User | #5
masterofollies
Senior Coder

 
Join Date: May 2005
Posts: 2,137
Thanks: 96
Thanked 72 Times in 72 Posts
masterofollies can only hope to improve
Appears to be missing an opening single quote before the 6.
__________________
Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?
masterofollies is offline   Reply With Quote
Old 03-29-2010, 06:28 PM   PM User | #6
mOrloff
Regular Coder

 
mOrloff's Avatar
 
Join Date: Nov 2008
Location: The Great Pacific NW, USA
Posts: 421
Thanks: 8
Thanked 6 Times in 6 Posts
mOrloff is an unknown quantity at this point
Ahh, I had searched for '6'', not noticing that the outer single-quotes were just delineating the string (without any results of course).

As for 6', there are probably a couple thousand matches to that tiny string. Do you have any pointers for a quick way to locate the problem ??

Going on the presumption that I picked up a stray apostrophe, I ran a find and ticked my way through the first 17 thousand rows, and all '6' strings were properly surrounded by commas, and my brain is becoming too numb to accurately plink through the rest of the records this same way.
Pointers ??

Quote:
Originally Posted by tomws View Post
... By the way, did you know you can insert multiple rows with one INSERT statement?...
No, I didn't. That's awesome.
I'll try to pull up some info on that. Thanks.
(Any further input is always welcome.)

Last edited by mOrloff; 03-29-2010 at 06:36 PM.. Reason: fixed typo: '6 -> 6'
mOrloff is offline   Reply With Quote
Old 03-29-2010, 06:35 PM   PM User | #7
mOrloff
Regular Coder

 
mOrloff's Avatar
 
Join Date: Nov 2008
Location: The Great Pacific NW, USA
Posts: 421
Thanks: 8
Thanked 6 Times in 6 Posts
mOrloff is an unknown quantity at this point
Quote:
Originally Posted by masterofollies View Post
Appears to be missing an opening single quote before the 6.
A search for ,6 comes up with no results as well.

~ mo
mOrloff is offline   Reply With Quote
Old 03-29-2010, 07:17 PM   PM User | #8
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
In the query call do you have an or die there that contains some idemtifying text and pronts out the failed query?
__________________
||||If you are getting paid to do a job, don't ask for help on it!||||
_Aerospace_Eng_ is offline   Reply With Quote
Old 03-29-2010, 07:17 PM   PM User | #9
tomws
Senior Coder

 
tomws's Avatar
 
Join Date: Nov 2007
Location: Arkansas
Posts: 2,644
Thanks: 29
Thanked 330 Times in 326 Posts
tomws will become famous soon enoughtomws will become famous soon enough
You can narrow it down by checking the last successfully inserted `partnumber` or `uniqueid`, then find that in the query dump. The next INSERT may be the problem.
__________________
Are you a Help Vampire?
tomws is offline   Reply With Quote
Old 03-29-2010, 08:02 PM   PM User | #10
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Run this:
Code:
SELECT @@sql_mode;
Followed by this:
Code:
SHOW CREATE TABLE `temp`;
And post the results please. Either through CLI or PHP will be fine, but make sure you view source to preserve the newlines.

Edit:
Also, can you post the PHP code you're using to build the SQL for the insertions please?
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 03-29-2010, 08:03 PM   PM User | #11
masterofollies
Senior Coder

 
Join Date: May 2005
Posts: 2,137
Thanks: 96
Thanked 72 Times in 72 Posts
masterofollies can only hope to improve
Quote:
Originally Posted by mOrloff View Post
A search for ,6 comes up with no results as well.

~ mo
You posted comma 6 which isn't a single quote. Either post the full script if possible, or search for every query that has 6 in it.

Also if it doesn't have 6, that means it's a pass query result, meaning the value from what is being inserted or updated is the value of 6, so it wouldn't show in the script.
__________________
Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?
masterofollies is offline   Reply With Quote
Old 03-29-2010, 10:09 PM   PM User | #12
mOrloff
Regular Coder

 
mOrloff's Avatar
 
Join Date: Nov 2008
Location: The Great Pacific NW, USA
Posts: 421
Thanks: 8
Thanked 6 Times in 6 Posts
mOrloff is an unknown quantity at this point
- PAUSE -

Thanks-a-bunch for all the help thus far.

I've gotta split, and will be offsite through all of tomorrow.
I will pick this back up on Wed morn.

Till then,
~ Mo

Thanks again.
mOrloff is offline   Reply With Quote
Old 03-29-2010, 10:16 PM   PM User | #13
mOrloff
Regular Coder

 
mOrloff's Avatar
 
Join Date: Nov 2008
Location: The Great Pacific NW, USA
Posts: 421
Thanks: 8
Thanked 6 Times in 6 Posts
mOrloff is an unknown quantity at this point
Quote:
Originally Posted by masterofollies View Post
You posted comma 6 which isn't a single quote...
Correct, that was based on the suggestion that an opening quote may have been missing.
If I understand correctly, that would lead to a string of something like ...'value',6','value',...

And, yes, you are correct, the values are getting passed into the sql via php vars.

See ya
~ Mo

Last edited by mOrloff; 03-29-2010 at 10:59 PM..
mOrloff is offline   Reply With Quote
Old 03-31-2010, 03:53 PM   PM User | #14
mOrloff
Regular Coder

 
mOrloff's Avatar
 
Join Date: Nov 2008
Location: The Great Pacific NW, USA
Posts: 421
Thanks: 8
Thanked 6 Times in 6 Posts
mOrloff is an unknown quantity at this point
Well, I'm back, and I suspect that the problem was in the data being grabbed for the INSERT rather than the script itself.
After a change of that file, everything seems to be working.

I'll post again if I hit another brick wall.

~ Mo

Last edited by mOrloff; 03-31-2010 at 03:57 PM..
mOrloff is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:51 PM.


Advertisement
Log in to turn off these ads.