Page 1 of 2 12 LastLast
Results 1 to 25 of 34
  1. #1

    Newbie- Simple ASP Help Please

    Hi.

    I am having trouble making my active server page scrip pull some records from a database and put them into a dropdown box. I think, haha.

    The code I am using is here, in a text file for you to read: www . joannemahoney . co . uk / cwk / customer_order1 . txt

    The problem is somewhere around the select box as far as I have gathered.

    The actual system is here: www . joannemahoney. co. uk / cwk / and if you log in with (user: test@joannemahoney.co.uk / pass: lewis) and try to place a new order, then 'add products to order' you will see my problem! Thank you if you can help at all, sorry to bother you if not!

    If you need anymore info then please let me know!

    I am a very large 'n00b' and I am only doing this for coursework at school but all your help is appreciated.

    (also sorry for the spaces in links, it wouldnt let me post without because i didnt have 5 posts!)

  2. #2
    Okay, I think I got a bit of it. The table in the sql query was spelt wrong.. I fixed that but now my script is timing out every time I try and run it. What are the causes? Help please! : )

  3. #3
    Okay - I lied. It stopped timing out but I'm having the same problem. Any offers?

  4. #4
    Join Date
    Jul 2002
    Location
    Victoria, Australia
    Posts
    36,941
    Since you want offers to help, moved to employment.

  5. #5
    Erm, I actually only wanted offers of help to troubleshoot this one page. I don't want to pay anyone to finish my coursework for me....

  6. #6
    Join Date
    Sep 2006
    Location
    Indiana
    Posts
    167
    Here's my take based on just looking at your code.

    Code:
    <SELECT name="productname">
    <%
    set conn=server.createobject ("adodb.connection")
    connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &_
    Server.MapPath("joannemahoney.mdb") & ";Persist Security Info=False"
    conn.Open connect
    set ors=server.createobject("adodb.recordset")
    strsql = "SELECT productid, bookstock, productname FROM tblProduct WHERE bookstock > 0 ORDER BY productid"
    ors.open strsql,conn
    Do while not ors.EOF
    if request.form("productname")=ors("productname") then
    response.write "<option value = '"&ors("productid")&"' Selected>"
    response.write ors("productname") & "</option>"
     
    ors.movenext
    end if
    loop
    %>
    </select>
    Try replacing the red code with the following. It should list all items in the database, but select the one that matches request.form("productname").

    Code:
    if request.form("productname")=ors("productname") then
     response.write "<option value = '"&ors("productid")&"' Selected>"
     response.write ors("productname") & "</option>"
    else
     response.write "<option value = '"&ors("productid")&"'>"
     response.write ors("productname") & "</option>"
    end if
    ors.movenext
    [Lurking Glass] <- Not a webhost.

  7. #7
    Ah, thank you very much! I was considering self-harm! Thanks so much again!

  8. #8
    Ah, I am now getting an error:

    Code:
    Microsoft OLE DB Provider for ODBC Drivers error '80040e07'
    
    [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.
    
    /cwk/customer_order1.asp, line 119
    Anything?

  9. #9
    Updated link with new code, new error still being recieved.

  10. #10
    Join Date
    Sep 2006
    Location
    Indiana
    Posts
    167
    I'm guessing the new error has something to do with this:

    Code:
    strsql = "SELECT * FROM tblOrderItems WHERE orderid = '"&orderid&"' "
    It's around line 110-115...I didn't check the new link yet.

    It's trying to get order IDs as text. I'd assume that order IDs are an integer or some similar field. And, if so, try removing the single-quotes around the field data...like this:

    Code:
    strsql = "SELECT * FROM tblOrderItems WHERE orderid = " & int(orderid)
    It wouldn't hurt to check that orderid is actually numeric before inserting it into the SQL string though. In the above code I wrapped it in the INT function to ensure that the orderid is numeric, but that isn't the ideal way to do it, as it'll still throw an error if the data is not numeric...but it won't execute it.
    [Lurking Glass] <- Not a webhost.

  11. #11
    Well it gets passed line 119 now, error on 121:

    Code:
    ADODB.Recordset error '800a0bcd'
    
    Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
    
    /cwk/customer_order1.asp, line 121
    All the tables in my database have entries in them, the error seems to be when the new order has no products already entered?

    Thanks so much for your help!

  12. #12
    Join Date
    Sep 2006
    Location
    Indiana
    Posts
    167
    Probably is this line:

    Code:
    orseof.movefirst
    Can't move to the first if there are no records. Either need to check if the opened recordset is already at EOF or omit the line.

    It can be omitted safely, as you open the recordset on the line above it. Recordsets open at the first record, so moving to the first is actually unnecessary.
    [Lurking Glass] <- Not a webhost.

  13. #13
    perfect, thank you!

  14. #14
    okay, new problem (should i make a new thread?) but a similar one.

    i am getting;

    Code:
    Microsoft OLE DB Provider for ODBC Drivers error '80040e07'
    
    [Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.
    
    /cwk/customer_orderproduct.asp, line 19
    when i run;

    Code:
    <!--#include file="logon.inc"-->
    <% 
    If Session("Email") = "" then
    Response.Redirect "login.asp"
    End if 
    
    productid = request.form("productid")
    quantity = request.form("quantity")
    orderid = request.form("orderid")
    
    dim orseof
    set db=server.createobject("adodb.connection")
    set orseof=server.createobject("adodb.recordset")
    db.open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & 
    
    Server.MapPath("joannemahoney.mdb") 
    
    strsql = "INSERT INTO tblOrderitems"
    strsql = strsql+"(orderid,productid,quantity)Values"
    strsql = strsql+"('"&orderid&"','"&productid&"','"&quantity&"')"
    orseof.open strsql,db
    
    dim orseof2
    set db=server.createobject("adodb.connection")
    set orseof2=server.createobject("adodb.recordset")
    db.open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & 
    
    Server.MapPath("joannemahoney.mdb") 
    
    strsql = "SELECT price FROM tblproduct WHERE productid = "&productid&" "
    orseof2.open strsql,db
    
    orseof2.movefirst
    price = orseof2("price")
    
    dim orseof3
    set orseof3=server.createobject("adodb.recordset")
    qrySQL = "SELECT subtotal FROM tblorder WHERE orderid = "&orderid&" "
    orseof3.open qrySQL,db
    
    orseof3.movefirst
    subtotal = orseof3("subtotal")
    
    subtotal = subtotal + price*quantity
    
    dim orseof4
    set db=server.createobject("adodb.connection")
    set orseof4=server.createobject("adodb.recordset")
    db.open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & 
    
    Server.MapPath("joannemahoney.mdb") 
    
    qrsql = "UPDATE tblOrder set subtotal='"&subtotal&"' where orderid="&orderid&"; "
    set orseof4=db.Execute (qrSql)
    
    response.redirect "customer_order1.asp?0rderid="&orderid&""
    
    %>
    all fields in the tblOrderItems are integers.

    Help please!

  15. #15
    Join Date
    Sep 2006
    Location
    Indiana
    Posts
    167
    Code:
    strsql = strsql+"('"&orderid&"','"&productid&"','"&quantity&"')"
    If all the fields are integers, the single-quotes need to go.

    Try:

    Code:
    strsql = strsql+"("&orderid&","&productid&","&quantity&")"
    [Lurking Glass] <- Not a webhost.

  16. #16
    I tried that already, I recieved a formatting error. I'll try again and write the result for you.

  17. #17
    Code:
    Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
    
    [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.
    
    /cwk/customer_orderproduct.asp, line 19
    Thats the exact error I get when I use your line of code. Thanks for all your help so far!

  18. #18
    Join Date
    Sep 2006
    Location
    Indiana
    Posts
    167
    Oh, didn't notice this before. But there are no spaces around the things in the INSERT statement. Try adding spaces around the "VALUES" keyword, and the column name and column value sets that are in parentheses. Basically, don't let any parts of the statement touch. Extra spaces are okay.
    [Lurking Glass] <- Not a webhost.

  19. #19
    Same error with this:

    Code:
    strsql = "INSERT INTO tblOrderItems"
    strsql = strsql+"( orderid , productid , quantity ) Values "
    strsql = strsql+"( "&orderid&" , "&productid&" , "&quantity&" ) "
    orseof.open strsql,db

  20. #20
    And same error with;

    Code:
    strsql = "INSERT INTO tblOrderItems"
    strsql = strsql + " ( orderid , productid , quantity ) Values "
    strsql = strsql + " ( "&orderid&" , "&productid&" , "&quantity&" ) "
    orseof.open strsql,db

  21. #21
    Join Date
    Sep 2006
    Location
    Indiana
    Posts
    167
    Hm, maybe it's something to do with trying to get a recordset out of an insert statement. I haven't been looking at this real close, as I haven't had time, but try this.

    Replace:
    orseof.open strsql,db

    With:
    db.Execute(strsql)

    Oh, and change the "+" symbols to "&".

    Actually, come to think of it...it's more likely that later that is causing the issues.
    [Lurking Glass] <- Not a webhost.

  22. #22
    It didn't seem to want to respond to any combination of those changes, I tried both db str commands with both + and & and get the same error each time!

  23. #23
    Join Date
    Sep 2006
    Location
    Indiana
    Posts
    167
    Hmmm.

    Are any of the database fields "AutoNumbers"? Any of the inserted values NULL or empty strings?

    What is the error it gives now that all the changes have been made?
    [Lurking Glass] <- Not a webhost.

  24. #24
    Error is exactly the same as before;

    Code:
    Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
    
    [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.
    
    /cwk/customer_orderproduct.asp, line 19
    All the inserted values have a value and, nope, none are autonumbers *shudder* haha.

    ASP is annoying

  25. #25
    Join Date
    Sep 2006
    Location
    Indiana
    Posts
    167
    Try this, add the following lines before you execute/open the statement.

    Response.Write(strsql)
    Response.End

    That'll spit out whatever the SQL string holds...and may give some insight as to what is going on. After doing that, post the result here, and I'll see if it looks to be problematic.
    [Lurking Glass] <- Not a webhost.

Page 1 of 2 12 LastLast

Posting Permissions

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