Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 8th, 2007, 12:38 PM
Authorized User
 
Join Date: Nov 2006
Posts: 14
Thanks: 2
Thanked 0 Times in 0 Posts
Send a message via Yahoo to webXtreme
Default IF ELSE Statement

Hello:

I am STUCK. I have a form that I need to perform a certain function based on your login information. Here's the info.

INSTRUCTION:
When the member logs in with their member id and password I first validate to make sure they are registered (THAT PART WORKS), then if they are a registered member I need to see if they already completed the form (if yes) display their contact information that's stored in the database then I also need to check if they applied for the position they clicked on (if yes) then I want to allow them to update that record.

-or-

If the member already completed the form display their contact information then check if they applied for that paticular position (if no) then I want to add a new record for each position they are applying for.

NOTE: The member contact information can be in the database once with multiple positions they're applying for. IF THIS MAKES ANY SENSE!!

Here's my form code:
<%@LANGUAGE="VBSCRIPT"%>
<!-- METADATA TYPE="typelib"
    FILE="C:\Program Files\Common Files\System\ado\msado15.dll" -->

<%Option Explicit%>








<title>Member Application</title>

    <script type="text/javascript" src="_script/hideFields.js"></script>



<div id="content_region" class="div_content_region">

<table border="0" width="600" cellspacing="0" cellpadding="0">
 <tr>
  <td colspan="2" valign="center" bgcolor="#006699"><img src="../gr/px.gif" width="1" height="15" alt="" border="0" />



<a href="../default.asp" class="crumb">NAEYC Home</a> > <a href="./" class="crumb">Get Involved</a> > Consulting Editors Panel

    </TD>
 </TR>
 <TR>
    <TD COLSPAN="2" VALIGN="TOP">
    <TABLE BORDER="0" CELLSPACING="2"><TR><TD>

    <h2> Consulting Editors for Young Children and NAEYC Publications Membership Application</h2>


<%
dim theMessage, SW, SQL, SQL1, SQL2, dob, conn, rsmem, pwd, esw, member_id, rslog, password
TheMessage=""
SW=0
If not isEmpty(Request.Form("login")) AND Request.Form("member_id") <> "" AND isNumeric(Request.Form("member_id")) then

password = Request.Form("password")
member_id = Request.Form("member_id")

if not isEmpty(Request.Form("member_id")) then
    set conn=server.CreateObject ("adodb.connection")
    conn.open Application("WebConnectionString")
    SQL1="Select * from applicant where member_id=" & Request.Form("member_id") & " and password='" & Request.Form("password") & "'"
    set rsmem=conn.Execute(SQL1)
    'if rsmem.EOF then
    ' response.redirect "register.asp?e=1&mem=" & Request.Form("member_id")
    'end if
    if not rsmem.EOF then
        pwd=rsmem("password")
        sw=1
        esw=1
        if rsmem("date_of_birth")="1/1/1900" then
            dob=""
        else
            dob=rsmem("date_of_birth")
        end if
else
    set conn=server.CreateObject ("adodb.connection")
    conn.open = Application("ConnectionString")
    sql2="Select * from logins where userid='" & Request.Form("member_id") & "'" & " and password='" & Request.Form("password") & "'"
    'Response.Write sql2
    Set rslog = conn.Execute(sql2)
        if not rslog.EOF then
            pwd=rslog("password")
            'set conn=server.CreateObject ("adodb.connection")
            'conn.open = Application("ConnectionString")
            sql="Select * from member where member_id=" & Request.Form("member_id") & " and expiration_date >= getdate()"
            'Response.Write sql
            Set rsmem = conn.Execute(sql)
            if rsmem.EOF then
                TheMessage="We can not validate your membership, please enter valid member id."
            else
                sw=1
            end if
        else
        Response.Redirect "../registerCouncil.asp?e=1&mem=" & Request.Form("member_id")
        end if
    end if
end if
end if

%>


    <p align="left"></p>
    <form method="POST" enctype="multipart/form-data" action="insert2.asp">
    <input type="hidden" name="DateSubmit" value="<%=Date%>">
    <input type="hidden" name="id" value="<%= member_id %>">
        <input type="hidden" name="type" value="<%= Request.Form("direction") %>" ID="Hidden1">
        <input type="hidden" name="passwd" value="<%= pwd %>" ID="Hidden79">
        <input type="hidden" name="AppType" value="Consulting" />
    <p>&nbsp;</p>

    <table width="95%" border="1" align="center" cellpadding="0" cellspacing="4">
      <tr>
        <td></td>
        <td width="67%"> </td>
      </tr>
      <tr>
        <td width="33%" bgcolor="#E0DFE3"><strong>First Name: </strong></td>
        <td><input name="AppFName" type="text" id="AppFName" size="50"></td>
      </tr>
      <tr>
        <td bgcolor="#E0DFE3"><strong>Last Name: </strong></td>
        <td><input name="AppLName" type="text" id="AppLName" size="50"></td>
      </tr>
      <tr>
        <td bgcolor="#E0DFE3"><strong>Address 1: </strong></td>
        <td><input name="AppAdd1" type="text" id="AppAdd1" size="50"></td>
      </tr>
      <tr>
        <td bgcolor="#E0DFE3"><strong>Address 2:<span class="style2"> <br>
        (Apt., Ste. #)</span> </strong></td>
        <td><input name="AppAdd2" type="text" id="AppAdd2" size="50"></td>
      </tr>
      <tr>
        <td bgcolor="#E0DFE3"><strong>City:</strong></td>
        <td><input name="AppCity" type="text" id="AppCity" size="50"></td>
      </tr>
      <tr>
        <td bgcolor="#E0DFE3"><strong>State:</strong></td>
        <td><input name="AppState" type="text" id="AppState" size="2" maxlength="2"></td>
      </tr>
      <tr>
        <td bgcolor="#E0DFE3"><strong>Zip Code: </strong></td>
        <td><input name="AppZip" type="text" id="AppZip" size="10" maxlength="10"></td>
      </tr>
      <tr>
        <td bgcolor="#E0DFE3"><strong>Home Phone: </strong></td>
        <td><input name="AppHomePh" type="text" id="AppHomePh" size="50"></td>
      </tr>
      <tr>
        <td bgcolor="#E0DFE3"><strong>Cell Phone: </strong></td>
        <td><input name="AppCellPh" type="text" id="AppCellPh" size="50"></td>
      </tr>
      <tr>
        <td bgcolor="#E0DFE3"><strong>Work Phone: </strong></td>
        <td><input name="AppWorkPh" type="text" id="AppWorkPh" size="50"></td>
      </tr>
      <tr>
        <td bgcolor="#E0DFE3"><strong>Email:</strong></td>
        <td><input name="AppEmail" type="text" id="AppEmail" size="50"></td>
      </tr>
      <tr>
        <td colspan="2">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="2">
          <p><em>Please limit answers to no more than <strong>250 words</strong> per question.</em></p></td>
      </tr>



      <div id="council" style="display: 'none';">
      <tr>
        <td valign="top" bgcolor="#E0DFE3"><p><strong>Question 1: </strong></p> </td>
        <td valign="top">What aspects of <em>Young Children</em> and the NAEYC books program are of most interest to you?</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><textarea name="AppQ1" cols="60" rows="5" id="AppQ1"></textarea></td>
      </tr>
      <tr>
        <td valign="top" bgcolor="#E0DFE3"><strong>Question 2: </strong></td>
        <td valign="top">Does your schedule permit dedicating an average of 4 to 6 hours per month to reviewing tasks? What times of the year are you not available? </td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><textarea name="AppQ2" cols="60" rows="5" id="AppQ2"></textarea></td>
      </tr>
      <tr>
        <td valign="top" bgcolor="#E0DFE3"><strong>Question 3: </strong></td>
        <td valign="top">What are your views on how NAEYC can meet the diverse needs of our wide range of members in our publications?</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><textarea name="AppQ3" cols="60" rows="5" id="AppQ3"></textarea></td>
      </tr>
      <tr>
        <td valign="top" bgcolor="#E0DFE3"><strong>Question 4: </strong></td>
        <td valign="top"> How do your interests and experience in the field match the goals of <em>Young Children</em> and the NAEYC books program? </td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><textarea name="AppQ4" cols="60" rows="5" id="AppQ4"></textarea></td>
      </tr>
      <tr>
        <td valign="top" bgcolor="#E0DFE3"><strong>Question 5: </strong></td>
        <td valign="top">The early childhood field is characterized by a wide range of relevant topics and work settings. Reviewers might bring to this panel interests and experience with specific content areas, age groups, and care and education settings. They might conduct research, serve as teacher educators, work directly with young children, or contribute to the field in other ways. Within this range, where do your strengths and interests lie? What kinds of articles and books do you think you will be best suited to review? </td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><textarea name="AppQ5" cols="60" rows="5" id="AppQ5"></textarea></td>
      </tr>
      <tr>
        <td bgcolor="#E0DFE3"><strong>Resume Upload: </strong></td>
        <td><input name="file" type="file" id="file" size="50"></td>
      </tr>
      </div>


      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td colspan="2"><h6>* One of the NAEYC Governing Board priorities is that &ldquo;NAEYC, as a high performing, inclusive organization will develop diverse leadership to meet the needs of the early childhood field.&rdquo; The NAEYC Governing Board and Staff believe that the mission is best achieved when there is commitment to diversity and inclusion as core values and when there are actions reflecting those values.</h6></td>
        </tr>
      <tr>
        <td>&nbsp;</td>
        <td>

            <div align="center">
              <input type="submit" name="Submit" value="Submit">
              </div></td>
      </tr>
    </table>

</form>
</TD></TR></TABLE>
</div>




THANKS SO MUCH - I NEED TO FIGURE THIS OUT ASAP

webXtreme
__________________
webXtreme
 
Old February 8th, 2007, 06:05 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What exactly are you having trouble with? What is actaully happening that you don't want to have happen, or what is not happenging that you would like to have happen?

One note: Interspersing server side code with html should always be avoided. I know that many books, tutorials, and examples show this technique and therefore beginners (and even advanced programmers) seem to think this is a good way to do things. You can save yourself a lot of trouble by encapsulating any code into classes and not putting if/else or any other logic directly into your HTML. Besides all the obvious problems (such as hard to read, hard to understand code) it also causes context switching that will put a big hit on your processor and performance.

Anyway - I am sure someone here can be of help, but please clarify what you are specifically asking.

Woody Z
http://www.learntoprogramnow.com
 
Old February 8th, 2007, 06:25 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Loads of people will help however very few will build the page for you. To get best results post your 'problematic code only'-- what you want to do (which you have done), specific errors, line numbers and illustrate which is the problematic line.

Personally I see a need to conditionaly render HTML for many reasons. Sure functions and re usable code does not need to be inside your HTML. IMO your code is easy to read and indented well.

Wind is your friend
Matt
 
Old February 8th, 2007, 08:16 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Matt: I conditionally render HTML all the time - but I never put code inside html, and I never put HTML inside asp pages.

I do agree the code shown was neatly indented.

Woody Z
http://www.learntoprogramnow.com
 
Old February 8th, 2007, 08:50 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

woodyz - I saw a message in there which I may have mis-interpreted, sorry if this is the case. I now think the way your following two comments read are ambiguos

;;;but I never put code inside html
Inside the tag its self - I often place ASP code inside HTML tags. Especially the value tags for form elements, I think we all do. Often use conditional styles in all sorts of <td> <div> tags etc for the class values.
Between the opening and closing tags - I do this all the time for conditionaly rendering the data inside cells etc...

;;;I never put HTML inside asp pages
I dont undertand this one at all

Once again, sorry if I have mis interpreted your comment

Wind is your friend
Matt
 
Old February 8th, 2007, 09:53 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You haven't misinterpreted me at all.

First of all... I don't mean to sound like a know-it-all. I do have a great deal of experience with high performance, high traffic, complex, and critical websites for a large corporation. A lot of programmers here have had similar jobs so that is no big deal - I know that. I just want to make it clear that I have had real experience with this on production commercial sites. Also, I don't do any commercial ASP work anymore as I am in the ASP.NET world now, and actually I mostly do back-end stuff.

Here is the thing. ASP (and other page scripting environments) make it easy to intersperse HTML and server side code. For a few little tests and simple websites for companies who are not worried about maintenance and extensibility - it is a reasonable thing to do. But it not a reasonable thing to do for a large, complex site (and even for small hobby sites if you want to spend more time having fun and less time debugging or re-writing code whenever you want to make changes).

So to restate the puzzling comment: "I never put HTML into an ASP page." How can this be? All that goes into my asp pages is VbScript code and include directives. All of my HTML is rendered dynamically. On the best sites I have worked on, 90% of this rendering has been done via XSLT transformations, and that is my preferred method. The HTML is stored as an XSLT document or snippets in a database (most commonly). Usually there will be xslt for the page layout, and other xslt to render various features like the navigation, forms, lists, and so on. The data that will appear in the page is also most typically stored in a database, and in some cases is XML, in other cases just typical database data. It is retrieved and converted into an XML document dynamically by the ASP code or sql stored procs, and then the XML is transformed using the XSLT to output the html. This is a very straight forward and powerful mechanism which allows you to design and deploy entirely new sites with a very small amount of work.

Additionally, I typically use a modified Front Controller pattern to handle requests, determine what processing to do, manipulate or retrieve data and redisplay the page or redirect the request.

There have been numerous implementations and variations on this theme, but essentially they all have the same purpose: To completely decouple the presentation from the application logic so that changes in design or functionality impact as little of the code as possible.

You can find various templating systems described on the internet, and in the early years (for me anyway - 97, 98, 99) I tried a bunch of these - and they can be very powerful. I still use some of these in some cases on sites I've worked on for years. They do the same thing (which is to keep the HTML and the VbScript completely separate) but just not as elegantly or flexibly.

It might sound like this is very complicated - but it is actually very simple - and in its simplest form it is very easy to do. Years ago we would write "components" in VbScript as classes that could render tables, grids, dropdowns, etc - the same things people are now doing with "controls" in environments like ASP.NET. All very neatly and simply. With a paradigm like this you can stop thinking about coding an option box or a table - you just instantiate the class for the control you want, set a few properties to point it at its data and metadata and it renders the html itself. When the marketing people have an emergency to re-design a site by the end of the week so it is ready for a conference presentation or whatever - it can actually be done.

Of course - there are dozens of portal systems like dotnetnuke (just to name one) now days, but just a few short years ago these things didn't exist.

Also - this isn't just for a brochure-ware site. The same concepts work well for stores, shopping carts, and just about anything else like wikis, forums, blogs, and so on.

Once a framework of this type is put into place, the only new code that has to be written is when a completely new feature is added. For example, if the framework doesn't currently have a blog and the marketing group requests a blog - there will be some code to write. But not much, since most of what a blog is is just a few "lists" used in a defined manner. You get the idea, I am sure.

Okay - that all might seem overkill, but here is why we started doing things like this: Complex sites with a lot of intertwined VbScript/HTML are a nightmare to maintain after a few years. They become fragile - which is where one fix breaks something else. Small sites start small, but if they are at all successful, they become big. Then performance issues start showing up. As IIS and the ASP environment process an ASP page it has to switch context each time it encounters a change from HTML to VBScript. This context switching makes things very slow, and is processor intensive. On a mildly complex site that all of a sudden becomes very popular you quickly get availability problems. In other words - the site slows to a crawl and you start getting time-outs and the site goes down (more or less). I worked on sites like this as a consultant back in the early days - the issue is not easy to solve - the code essentially has to be completely replaced to remove the context switching issue.

Anyway - I hope that was instructive. Once you start working with these ideas it opens up a whole lot of opportunity.

Woody Z
http://www.learntoprogramnow.com
 
Old February 8th, 2007, 10:36 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Your post sure is am eye opener, thank you for taking the time to write it. Frankly alot of it was new to me. Our company does build web sites on the scale you talk about. None of these web sites are done in ASP - A good example of this would be the Australian Financial Review site w w w. a f r a c c e s s . c o m (this site is the largest implimentation of MM FLEX on the web at present according to Adobe) I will chat to these object oriented colleauges and get thier opinion.

I am a script kiddie and enjoy being one. Your methodology seems very enterprising and interesting. I myself build business systems for the Australian Defence Force. As you can imagine its probably the most strict SOE most programmers will ever encounter. The privellage of getting administrative rights to servers or updating the very old versions of things such as frameworks is not an option. Everything I build is in classic ASP, perhaps I will stick my foot in the .net or object oriented world one day. I assume from what you say a great deal of high traffic web sites adopt this methodolgy you speak of?

If I get out of this SOE I have been in for so long I may look at it. As I said, thankyou for sharing your process. BTW have you any experience with LDAP binding to AD (http://p2p.wrox.com/topic.asp?TOPIC_ID=55800)?

Wind is your friend
Matt
 
Old February 8th, 2007, 11:29 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have no experience with active directory. I program and there are always folks on the job who do that sort of work.

All the stuff I discussed I have done in good old ASP until the last 4 or 5 years when .NET came along. There are big advantages with .NET - but most of what you see is at least as bad as the worst of the old ASP stuff. Whenever we are given more power, we get more chances and creative ways to mess everything up.



Woody Z
http://www.learntoprogramnow.com
 
Old February 9th, 2007, 10:13 AM
Authorized User
 
Join Date: Nov 2006
Posts: 14
Thanks: 2
Thanked 0 Times in 0 Posts
Send a message via Yahoo to webXtreme
Default

Hey mat41 and woodyz:

I've been reading your emails and they are very helpful. Once I get this problem fixed I'm going to take my html code out and start creating my pages that way. I am new to programming and so any help is always welcome.

To answer Woodyz questions (What exactly are you having trouble with? What is actaully happening that you don't want to have happen, or what is not happenging that you would like to have happen?)

I can't display the members information into the form fields, the page comes up with only the header and nothing else. I will break the code down:

********Connecting to database****************************************** ***
Dim connStr 'Holds the Database Connection Object
Dim rsApplicant 'Holds the recordset for the record to be updated
Dim strSQL 'Holds the SQL query for the database
Dim lngRecordNo 'Holds the record number to be updated
Dim sw2

'Create an ADO connection odject
Set connStr = Server.CreateObject("ADODB.Connection")
      Set rsApplicant = Server.CreateObject("ADODB.Recordset")

' defining database connection (connectionstring.asp)

        connStr.ConnectionString = path
        connStr.Provider = provider
        connStr.open

'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT * FROM AppData, WHERE member_id=" & Request.Form("member_id")

'Open the recordset with the SQL query
rsApplicant.Open strSQL, connStr
************************************************** ******************************

Now I'm trying to display members information into the form field. If members contact information exist, display in form (they should be able to update if needed). Also, if members contact information is in the database I need to also check and see if they're applying for a new job position or they want to update their questions on a job they already applied for. So I need to do two checks: 1)are they in the system already 2) are they applying for a new position or want to update their information on a position they already applied for.
************************************************** ******************************
<%
if not rsApplicant.eof then
sw2=1
else
sw2=0
   ' do while not rsApplicant.eof
%>

<form method="POST" enctype="multipart/form-data" action="insert2.asp">
<input name="AppFName" type="text" id="AppFName" size="50" value="<%if sw2=1 then Response.Write rsApplicant("AppFName") end if%>">

<%
    end if

%>

************************************************** ***************************

I'm only displaying the main part of the data. The test member is in the database, but their name will not appear in the field. Again, I need to display their information into the fields (if the exist), if not, open a blank form to allow them to add their information. Then I need to check if they are applying for a new position or they want to update their resume on a position they already applied for.

You guys are wonderful, thanks for your help.


webXtreme
 
Old February 9th, 2007, 10:26 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Very insightful posts woody and Matt. Woody is 100% correct though, most books that were/are being published get the reader in the habit of mixing HTML and ASP, it works. For a begininer this becomes law and that is how they begin to do things so, when the notion of splitting the presentation layer and the Business/Data layer up come about, its shell shock.

In my early days of ASP I was that person, my code was an absolute nightmare to maintain and began to dread going to work. ><

Eventually I got into the rhythm of breaking my code apart and my life became incresingly more simple (well as simple as a programmers life can be anyway).

Good stuff you guys. ^^

================================================== =========
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
if/else statement mussa Beginning PHP 5 July 3rd, 2006 06:06 PM
What does the @ do in the following statement? kenn_rosie VB.NET 2002/2003 Basics 1 March 15th, 2006 12:20 PM
Like Statement Nitin_sharma Oracle ASP 2 May 10th, 2005 12:18 AM
Like Statement Nitin_sharma Oracle 4 February 12th, 2005 01:46 PM
Like statement Nitin_sharma Classic ASP Databases 7 February 1st, 2005 11:12 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.