TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-10-2008, 09:46 AM   #1 (permalink)
The Wanderer
 
Join Date: Apr 2008
Posts: 12
Thanks: 7
Durux is on a distinguished road
Default Keep getting mySQL error No. 1064, but i can't seem to find the problem

Hello all, i keep geeting the 1064 mySQL error from an sql statement, yet the statement looks valid all the way through.

Here is the PHP script that should update the DB:
PHP Code:
function update($sql$date){
    
    
$link aaa_connect();
    
    
$sql2 str_replace("\n"""$sql);
    
$sql2 str_replace("\'""'"$sql2);
        
    
$result mysql_query($sql2$link);
    if(!
$result){die('Invalid query: '.mysql_error().'<br>Error No: '.mysql_errno());}
        
    
$array[0] = mysql_affected_rows();
        
    
$array[1] = date('l',mktime(0,0,0,substr($date62),substr($date9,2),substr($date,1,4))).' the '.date('j',mktime(0,0,0,substr($date62),substr($date9,2),substr($date,1,4))).'. of '.date('F',mktime(0,0,0,substr($date62),substr($date9,2),substr($date,1,4))).' '.date('Y',mktime(0,0,0,substr($date62),substr($date9,2),substr($date,1,4)));
        
    
mysql_close($link);
        
    return 
$array;
        

and here is the sql statement being given to the function:
Code:
UPDATE aaa_gallery SET date = '2008-04-10' WHERE hash = '7300ba4b247142ae68edc24029638129';
UPDATE aaa_gallery SET date = '2008-04-10' WHERE hash = '132f0d58ef38cd0cd91b56334b702efd';
UPDATE aaa_gallery SET date = '2008-04-10' WHERE hash = '19934c1a89b47724c1e7efe97dd84fcd';
UPDATE aaa_gallery SET date = '2008-04-10' WHERE hash = '3eecd1bf00faa7ebb3ca74bf9fbe379a';
i keep getting this error message back:
Code:
Invalid query: 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 '; UPDATE aaa_gallery SET date = '2008-04-10' WHERE hash = '132f0d58ef38cd0cd91b5' at line 1
Error No: 1064
Can anyone help me out with this one?

Last edited by Durux : 04-10-2008 at 10:11 AM.
Durux is offline  
Reply With Quote
Old 04-10-2008, 10:27 AM   #2 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

not reading it or testing fully (sorry but im at work) but going off the error message it seems somewhere your script is inserting '; before the UPDATE statement, check the string inputted into the function.

if this isnt the case, i will have a look later if no1 else answers before me :)
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 04-10-2008, 10:33 AM   #3 (permalink)
The Wanderer
 
Join Date: Apr 2008
Posts: 12
Thanks: 7
Durux is on a distinguished road
Default

Quote:
Originally Posted by sketchMedia View Post
it seems somewhere your script is inserting '; before the UPDATE statement, check the string inputted into the function.
Actually no, if you look in the end of the error message it says
Code:
WHERE hash = '132f0d58ef38cd0cd91b5'
wich is the second line in the sql statement.
Durux is offline  
Reply With Quote
Old 04-10-2008, 10:53 AM   #4 (permalink)
Jim
The Addict
 
Jim's Avatar
 
Join Date: Nov 2007
Location: the Netherlands
Posts: 281
Thanks: 2
Jim is on a distinguished road
Default

I says "near", this most of the times means "before". (bit difficult for people like me who dont have english as native language).

So the error is defenatelly in the first line. Since you use quotes around all text, maybe hash is a reserved SQL word?
__________________
Nunchaku! Who doesn't like martial arts? =)
Send a message via MSN to Jim Send a message via Skype™ to Jim
Jim is offline  
Reply With Quote
Old 04-10-2008, 11:01 AM   #5 (permalink)
The Wanderer
 
Join Date: Apr 2008
Posts: 12
Thanks: 7
Durux is on a distinguished road
Default

Quote:
Originally Posted by Jim View Post
Since you use quotes around all text, maybe hash is a reserved SQL word?
No hash is not a reserved word in mySQL, using it for fetching data in th DB without a problem...
Durux is offline  
Reply With Quote
Old 04-10-2008, 11:34 AM   #6 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

The standard MySQL library can only have one statement at a time. You're trying to use four UPDATE statements with a single call to mysql_query. In this case, you can manipulate the query (the WHERE clause) into just one statement since all of the rows to be updated will be given the same new date value.
Salathe is offline  
Reply With Quote
The Following 2 Users Say Thank You to Salathe For This Useful Post:
Durux (04-10-2008)
Old 04-10-2008, 01:50 PM   #7 (permalink)
The Wanderer
 
Join Date: Apr 2008
Posts: 12
Thanks: 7
Durux is on a distinguished road
Default

Quote:
Originally Posted by Salathe View Post
The standard MySQL library can only have one statement at a time. You're trying to use four UPDATE statements with a single call to mysql_query. In this case, you can manipulate the query (the WHERE clause) into just one statement since all of the rows to be updated will be given the same new date value.
Found that out, remade the PHP function so it it splits up the statement and then use a while loop to get all the statements into the DB.

Thanks to all people for trying to help
Durux is offline  
Reply With Quote
Old 04-10-2008, 06:18 PM   #8 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Quote:
Actually no, if you look in the end of the error message it says
Code:
WHERE hash = '132f0d58ef38cd0cd91b5'
wich is the second line in the sql statement.
Not quite sure how to respond to that tbh.

'WHERE' is actually part of your query not an error message.

so i wanst far from the mark as salathe said you cant have 2 querys hence why
anyway glad you got it sorted.
Code:
SET date = '2008-04-10' WHERE hash = '7300ba4b247142ae68edc24029638129';
UPDATE aaa_gallery SET date = '2008-04-10' WHERE hash = '132f0d58ef38cd0cd91b56334b702efd';
failed near ';
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 04-13-2008, 07:51 PM   #9 (permalink)
The Wanderer
 
Join Date: Apr 2008
Posts: 6
Thanks: 0
Garrett is on a distinguished road
Default

Quote:
Originally Posted by sketchMedia View Post
Not quite sure how to respond to that tbh.

'WHERE' is actually part of your query not an error message.

so i wanst far from the mark as salathe said you cant have 2 querys hence why
anyway glad you got it sorted.
Code:
SET date = '2008-04-10' WHERE hash = '7300ba4b247142ae68edc24029638129';
UPDATE aaa_gallery SET date = '2008-04-10' WHERE hash = '132f0d58ef38cd0cd91b56334b702efd';
failed near ';
PHP: mysqli::multi_query - Manual

That should get your started, that's the only way I know of trying to do multiple queries by the ";" separator. (Other than doing each query in a for or while.)
Garrett is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 12:39 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design