Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Fake Money Transfer
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Suamere
Starting Member

27 Posts

Posted - 07 February 2005 :  00:43:32  Show Profile  Visit Suamere's Homepage  Send Suamere an AOL message  Send Suamere a Yahoo! Message
My web site deals in Rupees (Legend of Zelda Currency). In each record, there is a column labeled Rupees. I have created a form in html, that allows a person to input a number of rupees to give, and who to give them to. All that I could accomplish is to add rupees to that person. The money is not taken from the person "Giving." And then, I need it to write an error if the person doesn't have the funds to give. Here is what I have so far:

Response.Buffer = True

Dim Rupees     'The rupees to be transferred
Dim GiveTo     'Who the rupees are going to
Dim RupeesFrom 'Who is giving the rupees

RupeesFrom = Session(strUserName) 'Once logged on this is the user
Rupees = Request.QueryString("Rupees") 'html form query
GiveTo = Request.QueryString("GiveTo") 'html form query

sql = "UPDATE Members "
sql = sql & "SET Rupees='" & Rupees & "'"
sql = sql & " Where ScreenName='" & GiveTo & "'"

conn.Execute sql


I assume I need to use an insert statement to find out how many rupees "RupeesFrom" has. And then maybe do an If statement, saying that if the rupees to give are greater than the rupees of that guy, then return an error, else do the update. Then I need to find out how many rupees the person getting them has, and actually add these new rupees to it.

The delima is that every money tutorial I go to goes WAY In depth with secure web sites and way more. I just need simple math and such. Whenever I try, though, the page doesn't work. Help?

If something goes wrong, find the source of the problem and break it's legs.

Edited by - Suamere on 07 February 2005 00:49:01

Doug G
Support Moderator

USA
6493 Posts

Posted - 07 February 2005 :  17:46:50  Show Profile
You'll probably want to use UPDATE statements to alter values in existing database records for the from and to users.

======
Doug G
======
Computer history and help at www.dougscode.com
Go to Top of Page

Suamere
Starting Member

27 Posts

Posted - 08 February 2005 :  17:24:14  Show Profile  Visit Suamere's Homepage  Send Suamere an AOL message  Send Suamere a Yahoo! Message
Okay, so... If I have a statement like

If the Giver has less rupees than what they are giving, Then
Write "You don't have enough Rupees to give"
Else
Update the Table, Set Receivers Rupees to equal their current rupees Plus The rupees that are being given.

Update the Table, Set Givers Rupees to equal their current rupees minus the rupees being given.
End If

In my mind, that statement is clear. But it's not in ASP. Now, I know how to use the Update property. I know how to use If-Then statements. I even know how to do math. But for some reason, when I write that statement in code, it straight doesn't work. So is that not good?

Example:

DSN Connection Here
Variables as Follows:
strUserName = The Giver
GiveTo = Receiver
Rupees = How much being transferred

If strUserName.Rupees>Rupees Then
Response.Write "You are an idiot"
Else
Update Members Set GiveTo.Rupees=GiveTo.Rupees+Rupees
Set strUserName.Rupees=strUserName.Rupees-Rupees
End If


If something goes wrong, find the source of the problem and break it's legs.
Go to Top of Page

Gremlin
General Help Moderator

New Zealand
7528 Posts

Posted - 09 February 2005 :  03:13:29  Show Profile  Visit Gremlin's Homepage
The code you have to execute isn't technically just ASP. What your executing (via ASP) is Structured Query Language (SQL).

An SQL Update Query would usually look something like

UPDATE Table, Set Fielda = a, fieldb = b WHERE fieldc = 'c'

Now to put that into ASP in the context of what your trying to do, you could code it something like this (I assume you already have a valid database created and open called objConn).

strSQL = "UPDATE Members Set Rupees = Rupees + " & Rupees & " WHERE Screenname = '" & strGiveTo & "'"
objConn.Execute(strSQL)
strSQL = "UPDATE Members Set Rupees = Rupees - " & Rupees & " WHERE Screenname = '" & strUserName & "'"
objConn.Execute(strSQL)

This also assumes the column type for "Rupees" is numeric rather than character.

Kiwihosting.Net - The Forum Hosting Specialists

Edited by - Gremlin on 09 February 2005 03:15:13
Go to Top of Page

Suamere
Starting Member

27 Posts

Posted - 09 February 2005 :  11:45:58  Show Profile  Visit Suamere's Homepage  Send Suamere an AOL message  Send Suamere a Yahoo! Message
I KNEW I'd be able to figure it out! Lol. After editing, uploading, logging on to my page, checking the results, and editing again, like 500 times, I figured out how to make everything else work. However, I would NEVER Have been able to figure out that sql math thing. I've been looking everywhere for how to do that, and tried my ways too. If anybody is searching for a similar problem, here is my final code, that works:


<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/ Physical Path to DB "

Response.Buffer = True

Dim Rupees
Dim GiveTo
Dim strUserName
Dim strSQL
Dim UserExists

UserExists = "No"
Rupees = Request.QueryString("Rupees")
GiveTo = Request.QueryString("GiveTo")
strUserName = Session("strUserName")

Set RS = Server.CreateObject("ADODB.recordset")
rs.Open "Select * from Members WHERE ScreenName='" & strUserName & "'", conn
Dim HasRupees
%>
<%do until rs.EOF%>
<%for each x in rs.Fields%>
<%
HasRupees = rs("Rupees")
%>
<%next
rs.MoveNext%>
<%loop
rs.close
%>


<%
rs.Open "Select * from Members WHERE ScreenName='" & GiveTo & "'", conn
%>
<%do until rs.EOF%>
<%for each x in rs.Fields%>
<%
UserExists = rs("CharacterName")
%>
<%next
rs.MoveNext%>
<%loop
rs.close
%>


<%
If CInt(Rupees) > CInt(HasRupees) or UserExists = "No" Then
Response.Write("Not enough Rupees, or no such user")
Else
strSQL = "UPDATE Members Set Rupees = Rupees + " & Rupees & " WHERE ScreenName = '" & GiveTo & "'"
conn.Execute(strSQL)
strSQL = "UPDATE Members Set Rupees = Rupees - " & Rupees & " WHERE ScreenName = '" & strUserName & "'"
conn.Execute(strSQL)

Response.Write("You have given " & Rupees & " Rupees to " & GiveTo & "<br><br>")
Response.Write("Return to your home page: <a href=memberpage.asp>Character Page</a>")
Response.Write(" Password is " & UserExists & "!<br> You now have " & HasRupees & " Rupees")
End If
%>

If something goes wrong, find the source of the problem and break it's legs.
Go to Top of Page

Gremlin
General Help Moderator

New Zealand
7528 Posts

Posted - 09 February 2005 :  18:47:01  Show Profile  Visit Gremlin's Homepage
You might want to remove all those <% %> delimiters, strictly speaking your not context switching at all (theres not HTML in your script) so you don't need most of them. Indenting code will also help readability a little as well. Also close and destroy your conn object (and RS) once finished too with a
conn.close
set conn = nothing
set RS = nothing


<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/ Physical Path to DB "

Response.Buffer = True

Dim Rupees
Dim GiveTo
Dim strUserName
Dim strSQL
Dim UserExists

UserExists = "No"
Rupees = Request.QueryString("Rupees")
GiveTo = Request.QueryString("GiveTo")
strUserName = Session("strUserName")

Set RS = Server.CreateObject("ADODB.recordset")
rs.Open "Select * from Members WHERE ScreenName='" & strUserName & "'", conn
Dim HasRupees

do until rs.EOF
  for each x in rs.Fields
    HasRupees = rs("Rupees")
  next
  rs.MoveNext
loop
rs.close

rs.Open "Select * from Members WHERE ScreenName='" & GiveTo & "'", conn
do until rs.EOF
  for each x in rs.Fields
    UserExists = rs("CharacterName")
  next
  rs.MoveNext
loop
rs.close

If CInt(Rupees) > CInt(HasRupees) or UserExists = "No" Then
  Response.Write("Not enough Rupees, or no such user")
Else
  strSQL = "UPDATE Members Set Rupees = Rupees + " & Rupees & " WHERE ScreenName = '" & GiveTo & "'"
  conn.Execute(strSQL)
  strSQL = "UPDATE Members Set Rupees = Rupees - " & Rupees & " WHERE ScreenName = '" & strUserName & "'"
  conn.Execute(strSQL)
  Response.Write("You have given " & Rupees & " Rupees to " & GiveTo & "<br><br>")
  Response.Write("Return to your home page: <a href=memberpage.asp>Character Page</a>")
  Response.Write(" Password is " & UserExists & "!<br> You now have " & HasRupees & " Rupees")
End If

conn.close()
set conn = nothing
set RS = nothing
%>

Kiwihosting.Net - The Forum Hosting Specialists

Edited by - Gremlin on 09 February 2005 18:49:35
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.21 seconds. Powered By: Snitz Forums 2000 Version 3.4.07