A little bit of help needed

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Cainnech
    New Member
    • Nov 2007
    • 132

    #1

    A little bit of help needed

    Hello guys,

    I'm a real newbie so sorry that I may ask stupid questions but I'm stuck:

    Code:
    <%
    Dim con,sql_update,name,form_id,data_source
    form_id = CInt(Request.Form("id"))
    data_source =  "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _ Server.MapPath("employees.mdb")
    
    
    name = "Select Name From users where id = " & form_id 
    
    If _
     name == "John" _ 
    Then _
       sql_update = "Update users Set status = 'True' where id = " & form_id _
    Else _
       sql_update = "Update users Set status = 'False' where id = " & form_id _
    End If
    
    
     
     Set con = Server.CreateObject("ADODB.Connection")
     con.Open data_source
     con.Execute sql_update
     con.Close
     Set con = Nothing
    Response.Redirect "showall.asp" 
    
    %>
    I've been deducting this from other code and I was quite proud of myself for writing this what to my opinion should work. But unfortunately it doesn't :-)
    I get the "Page cannot be displayed"-page.

    If anyone could help me to clarify for me what I'm doing wrong here, that would be very nice.

    Greets,
    Cainnech
  • CroCrew
    Recognized Expert Contributor
    • Jan 2008
    • 564

    #2
    Line 24: Response.Redire ct "showall.as p"

    Seems the logical starting place to look. Do you have a page called “showall.a sp” sitting in the same folder as the one that you post the code from?

    Regards,
    CroCrew~

    Comment

    • Cainnech
      New Member
      • Nov 2007
      • 132

      #3
      Yes it does.

      And that code works since I already use it on another page where I can delete records.

      Comment

      • jhardman
        Recognized Expert Specialist
        • Jan 2007
        • 3405

        #4
        if name == "John" ... in asp you do not use double = signs, just one. Also, the line continuation marks are unnecessary, and incorrect if you are using an "end if" statement:
        [code=asp]If name = "John" Then
        sql_update = "Update users Set status = 'True' where id = " & form_id
        Else
        sql_update = "Update users Set status = 'False' where id = " & form_id
        End If[/code]

        Make sure your friendly error messages are off, then sometimes you need to force the actual error message to show up (instead of the "page can not be displayed" message). One fast way to force the asp error message to show up is to substitute the text of the page with a simple "hello world" message that couldn't possibly contain an error. After you see the correct page, put the code back and hit refresh, this should show the asp error message.

        Let me know if this helps.

        Jared

        Comment

        • Cainnech
          New Member
          • Nov 2007
          • 132

          #5
          Originally posted by jhardman
          if name == "John" ... in asp you do not use double = signs, just one. Also, the line continuation marks are unnecessary, and incorrect if you are using an "end if" statement:
          This did the trick.

          I'll probably run into syntax-translation errors a lot more since I'm only used to program in Javascript.

          But thanks a lot Jared!

          Comment

          • Cainnech
            New Member
            • Nov 2007
            • 132

            #6
            I thought my problem was solved but not completely.

            Although it now changes the value to false even if my statement is true.
            I've looked into it and it seems that the value for "name" is completely off.

            Code:
            name = "Select Name From users where id = " & form_id  
              
            If name = "John"  Then  
               sql_update = "Update users Set status = 'True' where id = " & form_id
            this is what it says now.
            Unfortunately, the value of name now is : Select Name From users where id = 8

            Now I didn't open my database yet so he won't do it correctly s he has nowhere to look so I have to open my database and perform a sql lookup first.

            My problem now is that I don't know how to lookup a value in a database using SQL and store it into a variable.

            So basically what I want to do is;
            - lookup a value at a specified place in the database and store it in a variable (name in this case)
            - compare it to a predefined variable (John in this case)
            - update a different cell within the same id (status in this case)

            Help would be appreciated.

            Comment

            • jhardman
              Recognized Expert Specialist
              • Jan 2007
              • 3405

              #7
              when you say
              Code:
              name = "SELECT ..."
              you are just assigning a string variable. What you want is to execute a sql command and store the result in the variable. Does this make sense? Your original code shows how to execute a sql command (one of the last lines in the original code you posted). Unfortunately, I can't remember ever trying to look up a single value from a db using classic ASP. It seems like it should go something like this:
              Code:
              name = con.execute ("SELECT ...")
              Let me know if this works, otherwise I might be able to suggest something else.

              Jared

              Comment

              Working...