Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
This is a simple script, that doesn't work!
Old 06-21-2008, 08:02 PM This is a simple script, that doesn't work!
Sleeping Troll's Avatar
Ultra Talker

Posts: 351
Name: Butch Begy
Trades: 0
I figure I must be doing something really dumb! No errors, checked my strings and they are correct (I think), table does not update, any ideas?

Code:
 
<%
RespStr= "The item has been updated! Your cart will reflect changes."
CustID=Request.QueryString("CustID")
Qty=Request.QueryString("Qty")
ProdID=Request.QueryString("ProdID")
Set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open ("c:/inetpub/wwwroot/HawksWeb/Data/WebData.mdb")
SQL = "Update Cart Set Qty='"&Qty&"' Where ProdID='"&ProdID&"' and CustID='"&CustID&"'"
if Qty=0 then
SQL = "Delete From Cart Where ProdID='"&ProdID&"' and CustID='"&CustID&"'" 
conn.Execute SQL 
End If
Set conn=nothing
Response.Write(RespStr)
%>
I am inserting to the database just fine this script makes changes to existing data.

Last edited by Sleeping Troll; 06-21-2008 at 08:04 PM.. Reason: More info
Sleeping Troll is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-21-2008, 09:52 PM Re: This is a simple script, that doesn't work!
nyef's Avatar
Ultra Talker

Posts: 265
Name: Lucas
Trades: 0
Move the "conn.Execute SQL" to be BELOW the End If. Right now it's inside the If statement so it is ONLY executing when qty=0.
__________________
~nyef

Please login or register to view this content. Registration is FREE
nyef is offline
Reply With Quote
View Public Profile Visit nyef's homepage!
 
Old 06-22-2008, 06:39 AM Re: This is a simple script, that doesn't work!
Sleeping Troll's Avatar
Ultra Talker

Posts: 351
Name: Butch Begy
Trades: 0
Yeah, that is because I want to delete the record if the Quantity is "0", otherwise I want to update the record with a new quantity. This is weird, I cannot even get an error to work with. Thanks for the interest.
Sleeping Troll is offline
Reply With Quote
View Public Profile
 
Old 06-22-2008, 07:01 AM Re: This is a simple script, that doesn't work!
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
Yeah, that is because I want to delete the record if the Quantity is "0", otherwise I want to update the record with a new quantity
Yep, sure, BUT you have to execute the SQL statement in BOTH cases! In your code it will only execute in the one case!
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-22-2008, 07:16 AM Re: This is a simple script, that doesn't work!
Sleeping Troll's Avatar
Ultra Talker

Posts: 351
Name: Butch Begy
Trades: 0
DOH! Thx guys, my site is done!... for now.
Sleeping Troll is offline
Reply With Quote
View Public Profile
 
Old 06-22-2008, 12:56 PM Re: This is a simple script, that doesn't work!
nyef's Avatar
Ultra Talker

Posts: 265
Name: Lucas
Trades: 0
Also I might point out that the code you presented here is highly vulnerable to a SQL injection attack.

I could go to the page that uses that code, and change the url so instead of ProdId=15, I could enter the url:
Code:
yourdomain.com/updatecart.asp?qty=0&custid=0&ProdId=';delete from User;//
Guess what would happen?

With ProdId equal to:
Code:
';delete from User;//
The code that gets executed is:
Code:
Delete From Cart Where ProdID=0 and CustID='';delete from User;//'
That's right, it deletes from Cart where CustId='',
then it deletes EVERYTHING FROM THE USER TABLE
then a comment afterwards to prevent any errors.

Of course, you might not have a User table, but it would be a simple matter to instead of deleting the user table, executing some other code to determine what tables you have, THEN deleting those tables, or altering data, or doing whatever I felt like to royally screw over your database.

Whenever you have user input that goes into a sql statement,
you MUST replace apostrophes with double apostrophes,
or strip them out completely,
otherwise hackers WILL eventually find your site and have happy time with your database.
This is called a SQL injection attack and is one of the most widely used attacks on the internet.
__________________
~nyef

Please login or register to view this content. Registration is FREE
nyef is offline
Reply With Quote
View Public Profile Visit nyef's homepage!
 
Old 06-26-2008, 06:40 PM Re: This is a simple script, that doesn't work!
sandbox's Avatar
Extreme Talker

Posts: 153
Trades: 0
I second that nyef, Just had my site hacked with sql injection. I found a nice simple page that explains how to fix your asp code: http://www.cheergallery.com/SQLInjectionHelp.html

Better to fix it now that later, trust me on this.
__________________
¦
Please login or register to view this content. Registration is FREE
s ¦
Please login or register to view this content. Registration is FREE
¦
Please login or register to view this content. Registration is FREE
sandbox is offline
Reply With Quote
View Public Profile Visit sandbox's homepage!
 
Old 06-26-2008, 10:16 PM Re: This is a simple script, that doesn't work!
Sleeping Troll's Avatar
Ultra Talker

Posts: 351
Name: Butch Begy
Trades: 0
Thx guys, I was aware of the threat and the database is just a temp holder for customer order as is the ID just a temp until checkout, I was still going to have to protect them to some extent though and thought I was looking at another day or to of punching this keyboard... The script looks good and simple, will save me a ton of trouble sandbox!
Sleeping Troll is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to This is a simple script, that doesn't work!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.38374 seconds with 12 queries