If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > deleting data from database

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-25-04, 18:57
krills krills is offline
Registered User
 
Join Date: Sep 2004
Posts: 5
Exclamation deleting data from database

Ive just started learning ASP and i am using MySQL databases. So far ive managed to make a newsposting thing that allows me to insert news and read them. Now i want to have the option of deleting data from the database directly from the site, but whatever i try to write in the sql command it doesn't want to work. I don't know where i should ask this question but ill start here =)
ive read several guides but some of them are PHP guides or ASP but msaccess databases.
this is how my stuff looks at the moment:

(page name: newsremove.asp)
Code:
<%
if request("delid") <> "" then
 delid=request("delid")
 sql="DELETE * FROM news WHERE ID=" & delid
 conn.execute(sql)
end if
%>
<form action="newsremove.asp" method="post">
Type in the ID of the post you wish to remove: <input type="text" name="delid" size=20><br>
<input type="submit" value="remove this post!">
</form>
I also have this little part where i show all the news but i don't think it has anything to do with the errors i get.
Code:
do until rs.eof
 response.write "<hr align=left width=300 size=2 color=black noshading>"
 response.write rs("time") & " by " & rs("poster") & ". ID: " & rs("id")
 rs.moveNext
loop
The errors i get when i try to remove a entry is
"ADODB.Connection.1 (0x80004005)
SQLState: 42000 Native Error Code: 1064 [TCX][MyODBC]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 '* FROM news WHERE ID=9' at line 1
/newsremove.asp, line 25"

ANY HELP AT ALL IS VERY THX!

Last edited by krills; 09-26-04 at 07:41.
Reply With Quote
  #2 (permalink)  
Old 09-26-04, 13:37
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
the error message points to exactly where the problem is

remove the asterisk

DELETE FROM news WHERE ID=937
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 09-26-04, 14:38
krills krills is offline
Registered User
 
Join Date: Sep 2004
Posts: 5
:O what!? i dont need the *? im gona try and see =)
Reply With Quote
  #4 (permalink)  
Old 09-26-04, 14:44
krills krills is offline
Registered User
 
Join Date: Sep 2004
Posts: 5
another error

well, now i get my old friend "expected 'end' "

"Expected 'End'
/newsremove.asp, line 31, column 40"

Line 31 is the empty line between "if request("delid") = "" then" and "delid=request("delid")"

Code:
<form action="newsremove.asp" method="post">
		Type in the ID of the post you wish to remove: <input type="text" name="delid" size=20><br>
		<b>Make sure its the right one! Once you delete a post it can't be recovered!!</b><br>
		<input type="submit" value="Im sure, remove this post!">
		</form>
		<%
		
		if request("delid") = "" then
		
			delid=request("delid")
			sql="DELETE FROM news WHERE ID="& delid""
			set rs=conn.execute(sql)
		
		end if

		
		sql="SELECT * FROM news ORDER BY tid DESC"
		set rs=conn.execute(sql)
		
		do until rs.eof
			response.write "<hr align=left width=300 size=2 color=black noshading>"
			response.write rs("TID") & " by " & rs("POSTER") & ". ID: " & rs("ID")
			rs.moveNext
		loop
		%>
I get this friggin error all the time!! i know the answer is that i am missing a "end if" statement but i aint!! Please fast help is appreciated!
Reply With Quote
  #5 (permalink)  
Old 09-26-04, 15:30
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
i don't code in that particular scripting language, but it sure looks like you are trying to delete based on an id that isn't there

if request("delid") = ""
then
delid=request("delid")
sql="DELETE FROM news WHERE ID="& delid""
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 09-26-04, 16:29
krills krills is offline
Registered User
 
Join Date: Sep 2004
Posts: 5
hehe

hmm sounds very reasonable now that you mention it=) ill try it tomorrow now i gotta go to bed
Reply With Quote
Reply

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

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