Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Mar 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Asp probs.. Help please..

    Lets say I have this line;
    cn="DRIVER=SQL Server;UID=" & dbuser & ";PWD=" & dbpassword & ";DATABASE=Djiya_dusta;SERVER=" & dbserver & ";"
    sqla = array("INSERT INTO User_ITEMS (Us_ID, Item_ID) VALUES(22, 5486317)", _


    And lets say I have a variable that loads the UserID, the user ID should be loaded off of the database, I know how that goes.. Though... The userID that's been loaded off of the Database should be inserted into the space where "22" is.

    So.. Something like;
    ("INSERT INTO User_ITEMS (Us_ID, Item_ID) VALUES(<LOADEDUSERID>, 5486317)", _

    How do I do this? Any idea's..?

    Cause since the line is inbetween two " "'s it's hard..

  • #2
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can break out of the string

    Code:
    user_id = 1
    
    sql = "INSERT INTO table (id, name) VALUES (" & user_id & ", 'Joe')"

  • #3
    New to the CF scene
    Join Date
    Mar 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you for the info! It helped! ^^

    But one last problem I have;

    Lets say that I have a amount of money in another table, but trough the script I want to access that table and reduce the amount of the money, how do I do that, any tips?

    So basically I have 200 bucks in the table "User_ID_Mon", how do I reduce that with 70?

  • #4
    Registered User
    Join Date
    Jan 2006
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Update User_ID_Mon Set Amount=70 Where User_ID=22


    Assuming

    User_ID_Mon = the table
    Amount = the column that the amount is stored in
    User_ID = the where criteria you want to use.

  • #5
    New to the CF scene
    Join Date
    Mar 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    cn="DRIVER=SQL Server;UID=" & dbuser & ";PWD=" & dbpassword & ";DATABASE=Money_Amount;SERVER=" & dbserver & ";"
    sqla = array("USERINFO Set Cash_Amt-70 Where User_ID="&session("userid")&),_
    I was talking about something like that actually.. But that does not work, I get an error.. I want it to reduce 70 cash off of my current cash..

    Database; Money_Amount
    Table; USERINFO
    Column; Cash_Amt


    Anyone knows..?

  • #6
    Registered User
    Join Date
    Jan 2006
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ah...I gotcha.

    You need to have a recordset opened with what the current cash is...then it would simply be...

    Update USERINFO Set Cash_Amt=" & (RS("CurrentAmount) - 70) & " Where User_ID=22

    Edit: Assuming of course you want it to be dynamic...

  • #7
    New to the CF scene
    Join Date
    Mar 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Mmm.. Did not quite work well either.. =(
    I'll post the whole code here, maybe then things will be easier..

    Code:
    <%
    If Session("UID") = "" Then
    	Response.Redirect "login.asp"
    End If
    %>
    <!--#include file="common.asp"-->
    <%
    x_userid = request("userid")
    x_Password = request("Password")
    
    x_ID = request("UID")
    
    Set conn = Server.CreateObject("ADODB.Connection")
    conn.Open ConnStr
    sSql = "SELECT userid, UID, password, Logon FROM PangYa_Member_Info WHERE UID='"& session("UID") &"'"
    Set rs = Server.CreateObject("ADODB.Recordset")
    rs.Open sSql, conn
    If rs("Logon") = 1 Then
    If not rs.Eof Then
      x_UID = rs("UID")
    Response.Redirect "error.html"
    End If
    End If
    %>
    
    <%
    x_pang=0
    x_cookie=0
    Set conn = Server.CreateObject("ADODB.Connection")
    conn.Open ConnStr
    sSql = "SELECT pang FROM PangYa_User_Statistics WHERE UID='"& session("UID") &"'"
    Set rs = Server.CreateObject("ADODB.Recordset")
    rs.Open sSql, conn
    If not rs.Eof Then
      x_pang = rs("pang")
    End If
    rs.close
    Set conn = Nothing
    
    Set connx = Server.CreateObject("ADODB.Connection")
    connx.Open xConnStr
    sSql = "SELECT Cash_Amt, Bonus_Amt FROM BX_TG_USERINFO WHERE User_ID='"& session("userid") &"'"
    Set rs = Server.CreateObject("ADODB.Recordset")
    rs.Open sSql, connx
    If not rs.Eof Then
      x_cookie = rs("Cash_Amt")
    End If
    rs.close
    Set connx = Nothing
    %>
    
    <%
    Update BX_TG_USERINFO Set Cash_Amt=" & (RS("CurrentAmount) - 70) & " Where User_ID=22
    %>

    Maybe now I can be pointed to what I did wrong..? x3

    Thanks very much for all the help! =)
    Last edited by Atlantastar; 03-24-2006 at 10:53 PM.

  • #8
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,072
    Thanks
    4
    Thanked 8 Times in 8 Posts
    You don't need a recordset opened!! you can do the subtraction right in the SQL statement.

    Update BX_TG_USERINFO Set Cash_Amt= (Cash_Amt - 70) Where User_ID=22


    Also if these are opening the same database then you dont need all of those connection objects!!! You only need 1 per database. Any more than that is slowing down the execution of the script and the loading of your page. Note that I said per database not per table.

    Also you really should declare your variables before use. It is a very bad habit that some lazy programmers get into by not declaring variables 1st. Using OPTION EXPLICIT at the top of the page and then declaring variables helps debug. Plus by declaring variables before use it speeds up execution of the script. As an aside if you ever move into vb.net or C++ you will have to start declaring those variables.

    Also if you are not going to reuse the object later in the page, then you need to release the objects after you close them. Otherwise they are still held in server memory until the session ends

    Another item is you should not use the delimiters just to seperate code block if you are not moving into html. Each time you break up your <% %> tags to write html, you cause the compiler to call Response.WriteBlock. Each time you seperate the code sections with the delimiters, it has to render it by calling Response.WriteBlock over and over again. Once for each time you broke up the asp script delimiters. Limiting the number of times you do the delimiters saves cycles and memory and increases the speed of the ASP code execution.

    Code:
    <!--#include file="common.asp"-->
    <%
    If Session("UID") = "" Then
    	Response.Redirect "login.asp"
    End If
    
    x_userid = request("userid")
    x_Password = request("Password")
    
    x_ID = request("UID")
    
    Set conn = Server.CreateObject("ADODB.Connection")
    conn.Open ConnStr
    sSql = "SELECT userid, UID, password, Logon FROM PangYa_Member_Info WHERE UID='"& session("UID") &"'"
    Set rs = Server.CreateObject("ADODB.Recordset")
    rs.Open sSql, conn
    If rs("Logon") = 1 Then
    	If not rs.Eof Then
    		x_UID = rs("UID")
    		rs.Close   'close and release both your objects before you do a redirect
    		Set rs = Nothing
    		Conn.Close
    		Set Conn = Nothing
    		Response.Redirect "error.html"
    	End If
    End If
    
    rs.Close 'close object but don't release it so that it can be reused
    
    x_pang=0
    x_cookie=0
    sSql = "SELECT pang FROM PangYa_User_Statistics WHERE UID='"& session("UID") &"'"
    rs.Open sSql, conn
    If not rs.Eof Then
      x_pang = rs("pang")
    End If
    rs.close   'close object but don't release it so that it can be reused
    conn.Close  'close and release connection object
    Set conn = Nothing
    
    'I am assuming because of the different connectionstring that this is opening a new database
    Set connx = Server.CreateObject("ADODB.Connection")  
    connx.Open xConnStr
    sSql = "SELECT Cash_Amt, Bonus_Amt FROM BX_TG_USERINFO WHERE User_ID='"& session("userid") & "'"
    rs.Open sSql, connx
    If not rs.Eof Then
      x_cookie = rs("Cash_Amt")
    End If
    rs.close
    Set rs = Nothing
    connx.Close
    Set connx = Nothing
    %>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •