Page 1 of 4 123 ... LastLast
Results 1 to 10 of 40

Thread: asp newbie

  1. #1
    Join Date
    Jan 2004
    Posts
    2,011
    Rep Power
    0

    Default asp newbie

    first of all asp feels really limited compared to php, less logical as well. but ne way. i'm here doing the basics, i'm at cookies now. what i'ld like to now is the scope of a cookie isn't it global, i.e i thought based on the fact that the cookie is created on my machine and expiration date for it set to say two months time. it would be accessible from where ever i choose all i'ld need to do is get the cookie name correct. the lil test that i'm doing is failing the cookie only prints on the page that i create it. basically i'm trying to do something where a user's fnam and lname are always printed in the respective text boxes as long as he / she has visited the page previously. sessions would't work for this so i thought cookies would be the way.

  2. #2
    Join Date
    Jan 2004
    Posts
    2,011
    Rep Power
    0

    Default

    k two pages. aspform.asp and aspcookie.asp aspform posts its values to the aspcookie.asp page. the cookies are created on the aspcookie.asp page with the following code:

    Code:
            Response.Cookies("fname")= Request.Form("fname")
    	Response.Cookies("lname")= Request.Form("lname")
    	Response.Cookies("fname").Expires=#june 1, 2005#
    	Response.Cookies("lname").Expires=#june 1, 2005#
    now what i was hoping to do is access the fname and lname cookies on the aspform.asp page and echo i mean Response.Write them to their respective form elements. see source below:

    Code:
         <form name="form1" method="post" action="aspcookies.asp">
       <%      
       	fname = Request.Cookies("fname")
    	lname = Request.Cookies("lname")
    	%>
      <label>fname</label>&nbsp;&nbsp;&nbsp;<input name="fname" type="text" id="fname" value="<% Response.Write(fname)%>">
      <label>lname</label>&nbsp;&nbsp;&nbsp;<input name="lname" type="text" id="fname" value="<% Response.Write(lname)%>">
      <input name="submit" type="submit" value="Submit">
    </form>
    has any body got any answers for me? where are ASP veterans.
    Last edited by death_knight; May 27, 2005 at 05:36 PM.

  3. #3
    Join Date
    Jan 2004
    Posts
    2,011
    Rep Power
    0

    Default

    hmm well it works it was I.E being a loser it works fine in firefox. i dont get it though. cuase the cookies aren't turned off in i.e so it should work fine as well.
    Last edited by death_knight; May 27, 2005 at 05:57 PM.

  4. #4
    Join Date
    Apr 2003
    Posts
    13,269
    Rep Power
    34

    Default

    It would be preferable if you do your testing and coding in firefox or any other W3C standard compliant browser first, then check if it works in IE afterwards.

    Your code looks ok and should work as you found out. Your cookie can only be accessed from the website you set it from. You can restrict the scope of a cookie by setting the cookie Path.

    Code:
    'This cookie can be accessed from any page on the website that set it.
    Response.Cookie("Cookie") = "Chip"
    Response.Cookie("Cookie").Path = /
    
    'This cookie can only be accessed from any page in the "chocolate" folder.
    Response.Cookie("Cookie") = "Chip"
    Response.Cookie("Cookie").Path = "/chocolate/"
    "The best software is the one that fits your needs." - A_A

    Virus free since: date unknown
    Anti-virus free since: August 2008

  5. #5
    Join Date
    Jan 2004
    Posts
    2,011
    Rep Power
    0

    Default

    respect arch. didn't know about that path attribute cookies.

  6. #6
    Join Date
    Jan 2004
    Posts
    2,011
    Rep Power
    0

    Default

    um can anybody assist with database connections and queries. i'm not sure how to do this with asp. i'm working with a mssql backend i need to know how to connect to it and run queries on it. if there is any syntactical difference from mysql i also need to know what. a tutorial would be nice so if you know ne online point me in that direction i have little time left ot learn all i need to so please help is kindly appreciated.

  7. #7
    Join Date
    Apr 2003
    Posts
    13,269
    Rep Power
    34

    Default

    Here's an example of a database connection:

    Code:
    <%
    Set cnn = Server.CreateObject("ADODB.Connection")
    cnn.open "PROVIDER=SQLOLEDB;DATA SOURCE=sqlservername;UID=username;PWD=password;DATABASE=mydatabasename"
    
    strSql = "SELECT ID, NAME, DATE  FROM EXAMPLE_TABLE"
    
    set rs = cnn.execute(strSql)
    
    if rs.EOF or rs.BOF then
       'code to handle when no records were found goes here
    else
       intID = rs("ID")
       strName = rs("NAME")
       dteDate = rs("DATE")
    end if
    
    'close recordset
    rs.close
    set rs = nothing
    
    'close connection
    cnn.close
    set cnn = nothing
    
    %>
    There are so many variations on connecting to a database and how to get the records. This is just one of the ways.
    "The best software is the one that fits your needs." - A_A

    Virus free since: date unknown
    Anti-virus free since: August 2008

  8. #8
    Join Date
    Sep 2004
    Posts
    356
    Rep Power
    0

    Default

    what is the world coming to mr DK him self gone ASP my God DWL LMAO I remember the days when I went in the php section him a preach php gospel to mi but seriously what happen to DK a somebody force you are you just curious. I get to live best of both world now I am carzy about php now but my first love is ASP mi deh ya fi help you Mr. PHP guru

  9. #9
    Join Date
    Jan 2004
    Posts
    2,011
    Rep Power
    0

    Default

    respect arch. um question though regarding the keywords

    is the PROVIDER keyword for the type of database. what is sqloledb "well really its the 'ole' that i'm unsure of" the rest i figured out.

    @madhacker.
    hey man i love php dont get me wrong its my web dev version of c++ but i got work to do in asp for a client i cant turn em away would be better if i quit my job. so i've gotta learn. then i've gotta do .net cause pretty soon the same guy wants to migrate from asp to .net.
    Last edited by death_knight; Jun 10, 2005 at 02:11 AM.

  10. #10
    Join Date
    Sep 2004
    Posts
    356
    Rep Power
    0

    Default

    so why did the client insist that you use ASP what are you moding the Actual ASP script to do something else deh ya still if you need mi a good tutorial is @ http://w3cschools.com mi deh inna New Kingston (mi know seh u deh near deh so gi mi a shout when u in a problem with it )

Posting Permissions

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