User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 330,294 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,933 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser:
Views: 190 | Replies: 10 | Solved
Reply
Join Date: Aug 2004
Posts: 17
Reputation: ray_broome is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
ray_broome ray_broome is offline Offline
Newbie Poster

MySQL Error 1064 when DELETEing

  #1  
6 Days Ago
I'm trying to carry out the following delete statements
DELETE FROM images AS i WHERE i.image_id = 803 AND i.plant_num = 2277 LIMIT 1
DELETE FROM images AS i WHERE i.image_id = 804 AND i.plant_num = 2277 LIMIT 1
DELETE FROM images AS i WHERE i.image_id = 805 AND i.plant_num = 2277 LIMIT 1

but i am getting the error:
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 'AS i WHERE i.image_id = 803 AND i.plant_num = 2277 LIMIT 1; DELETE FROM images A' at line 1

any idea what is causing this because everything looks okay to me.

Thanks in advance
Last edited by ray_broome : 6 Days Ago at 2:21 pm.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2007
Posts: 77
Reputation: mwasif is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 5
mwasif mwasif is offline Offline
Junior Poster in Training

Re: MySQL Error 1064 when DELETEing

  #2  
6 Days Ago
Write statements without aliase e.g.
DELETE FROM images WHERE image_id = 803 AND plant_num = 2277 LIMIT 1;
Reply With Quote  
Join Date: Aug 2004
Posts: 17
Reputation: ray_broome is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
ray_broome ray_broome is offline Offline
Newbie Poster

Re: MySQL Error 1064 when DELETEing

  #3  
6 Days Ago
thanks, i tried doin that but still get the same basic error.

Query:
DELETE FROM images WHERE image_id = 803 AND plant_num = 2277 LIMIT 1;
DELETE FROM images WHERE image_id = 804 AND plant_num = 2277 LIMIT 1;
DELETE FROM images WHERE image_id = 805 AND plant_num = 2277 LIMIT 1;

Error:
Could not update the database:
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 '; DELETE FROM images WHERE image_id = 804 AND plant_num = 2277 LIMIT 1; DELETE F' at line 1

and here's a PHP snippet:
foreach($removals as $id)
	$sql .= "\nDELETE FROM images WHERE image_id = ".$id." AND plant_num = ".$_REQUEST['pid']." LIMIT 1;";
Last edited by ray_broome : 6 Days Ago at 3:49 pm.
Reply With Quote  
Join Date: Sep 2007
Location: North Bay Ontario
Posts: 172
Reputation: trudge is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 20
trudge trudge is offline Offline
Junior Poster

Re: MySQL Error 1064 when DELETEing

  #4  
6 Days Ago
What does your PHP query statement print out as? I'm betting it's not what you think it is.

Also, a
describe images
would help us help you.
Amer Neely - Web Mechanic
"Others make web sites. We make web sites work!"
Reply With Quote  
Join Date: Aug 2004
Posts: 17
Reputation: ray_broome is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
ray_broome ray_broome is offline Offline
Newbie Poster

Re: MySQL Error 1064 when DELETEing

  #5  
6 Days Ago
well the query i showed you is what prints out.
DELETE FROM images WHERE image_id = 803 AND plant_num = 2277 LIMIT 1;
DELETE FROM images WHERE image_id = 804 AND plant_num = 2277 LIMIT 1;
DELETE FROM images WHERE image_id = 805 AND plant_num = 2277 LIMIT 1;

and describe images is:
Field 	       Type 	                   Null 	Key 	Default 	Extra
image_id          int(10) unsigned 	   NO 	PRI 	NULL 	auto_increment
plant_num        int(10) unsigned 	   NO 	MUL 	NULL 	 
image_src 	       varchar(255) 	   NO 	  	NULL 	 
image_alt 	       varchar(64) 	   NO 	  	NULL 	 
location_taken  varchar(64) 	   YES 	  	Barbados 	 
is_vouchered    tinyint(1) 	   NO 	  	0 	 
is_best_fit 	       tinyint(1) 	   NO 	  	0 	 
Last edited by ray_broome : 6 Days Ago at 4:39 pm.
Reply With Quote  
Join Date: Sep 2007
Location: North Bay Ontario
Posts: 172
Reputation: trudge is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 20
trudge trudge is offline Offline
Junior Poster

Re: MySQL Error 1064 when DELETEing

  #6  
6 Days Ago
What does
SELECT * FROM images WHERE image_id = 803 AND plant_num = 2277\G

show you? If you can't find that image, then obviously you can't delete it.
Amer Neely - Web Mechanic
"Others make web sites. We make web sites work!"
Reply With Quote  
Join Date: Aug 2004
Posts: 17
Reputation: ray_broome is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
ray_broome ray_broome is offline Offline
Newbie Poster

Re: MySQL Error 1064 when DELETEing

  #7  
6 Days Ago
nope i get back a result

btw i'm connecting as a user with delete priviliges so it isnt that either

i thought it might be the "\n" in the sql string perhaps but i took it out and still got the error

thanks for the assistance so far, i hope someone can help cause i reallly need to try and get this finished up soon
Reply With Quote  
Join Date: Sep 2007
Location: North Bay Ontario
Posts: 172
Reputation: trudge is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 20
trudge trudge is offline Offline
Junior Poster

Re: MySQL Error 1064 when DELETEing

  #8  
6 Days Ago
Can you execute
DELETE FROM images WHERE image_id = 803 AND plant_num = 2277 LIMIT 1;
from the command line?

Can you execute that literal string from your script?

Your script might not have the same permissions you do from the command line. Do other of your scripts execute OK when accessing the database?

1064 seems to refer to using a reserved word, but I see none in your query.
Last edited by trudge : 6 Days Ago at 6:33 pm.
Amer Neely - Web Mechanic
"Others make web sites. We make web sites work!"
Reply With Quote  
Join Date: Aug 2004
Posts: 17
Reputation: ray_broome is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
ray_broome ray_broome is offline Offline
Newbie Poster

Re: MySQL Error 1064 when DELETEing

  #9  
5 Days Ago
Hi thanks for all the previous help but i've figured it out.

This is the php/sql query i use now:

php:
$sql .= "\nDELETE FROM images WHERE plant_num = ".$_REQUEST['pid']." AND image_id IN (".implode(",",$removals).");";

query
DELETE FROM images WHERE plant_num = 2277 AND image_id IN (803,804,805);

I'm not sure why, but MySQL didnt seem to like when i put DELETE statements one after the other like that
Last edited by ray_broome : 5 Days Ago at 7:04 pm.
Reply With Quote  
Join Date: Sep 2007
Location: North Bay Ontario
Posts: 172
Reputation: trudge is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 20
trudge trudge is offline Offline
Junior Poster

Re: MySQL Error 1064 when DELETEing

  #10  
5 Days Ago
Huh. Yes that is very strange. Glad you got it figured out though. And thanks for posting the solution in case someone else runs into this.
Amer Neely - Web Mechanic
"Others make web sites. We make web sites work!"
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

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

 

DaniWeb Marketplace (Sponsored Links)
Thread Tools Display Modes

Other Threads in the MySQL Forum

All times are GMT -4. The time now is 6:39 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC