 |
| 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
|
|
|
|

February 9th, 2007, 11:50 AM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Well, I just want to state that you guys posts WERE very enlightening! However, as dparsons stated, this IS ASP for BEGINNERS therefore the things you mention are not helpful to us beginners, at the PRESENT moment, because you are speaking on an advanced level. Some of things I was reading, would require me to go learn the techniques YOU suggest and THEN go fix my problem. NOT that THAT is NOT how things are supposed to be done anyway.. but when YOU have DEADLINES to meet, that is sometimes out of the question. And me personally, YES I am a beginner, NO i have not posted a whole lot of posts on this forum, HOWEVER, I do not see how anyone was of very much use to the originator of the post... other than the fact that you told him to display the code dealing with his problem, rather than all of it.. which was, in my opinion, the best advice that was given throughout the whole discussion.
Great information from all of you. But it seemed like you were more in competition for who knows the most rather than trying to assist.
|
|

February 9th, 2007, 12:06 PM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I'm a beginning programmer myself, so I don't know much.... but where u have this..
Code:
<%
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 would change to
<%if sw2=1 then%>
<form method="POST" enctype="multipart/form-data" action="insert2.asp">
<input name='AppFName' type='text' id='AppFName' size='50' value='<% rsApplicant("AppFName")%>'>
<%else%>
<form method="POST" enctype="multipart/form-data" action="insert2.asp">
<input name='AppFName' type='text' id='AppFName' size='50' value='
<%rsApplication("somethingelse")%>'>
<%end if%>
Quote:
quote:Originally posted by webXtreme
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> </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"> </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> </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> </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> </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> </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> </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> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="2"><h6>* One of the NAEYC Governing Board priorities is that “NAEYC, as a high performing, inclusive organization will develop diverse leadership to meet the needs of the early childhood field.” 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> </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
|
|
|

February 9th, 2007, 12:11 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
You have an error in your SQL Syntax:
strSQL = "SELECT * FROM AppData, WHERE member_id=" & Request.Form("member_id")
The comma after AppData shouldnt be there, but your not using On Error Resume Next so that error should not be supressed??
Also this logic is incorrect:
' 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%>">
<%
You will wind up writing out a <form> tag for every record in your record set and, on top of that, while the data in the text box will change, you will have no way to access the data because you never change the name of the form element, they will all be named: AppFName
Outside of an error though, I can't see why you are not getting your data displayed. Post back with any changes.
================================================== =========
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^^
================================================== =========
|
|

February 9th, 2007, 12:25 PM
|
|
Authorized User
|
|
Join Date: Sep 2006
Posts: 74
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
There we go ;)
T.B.
[email protected]
|
|

February 9th, 2007, 12:55 PM
|
|
Authorized User
|
|
Join Date: Nov 2006
Posts: 14
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
Thanks MissKaos99 but that didn't work I received an Syntax error in FROM clause. However, I think you gave me an idea I'm going to try.
dparsons: my system isn't reading that line because it's commented out.
<%
' do while not rsApplicant.eof
%>
This is fustrating because it need to go live on Monday :(
If I had more time, I would still have my hair (LOL)...
webXtreme
|
|

February 9th, 2007, 01:04 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
I understand that its commented out, but it is still there so I thought it was worth mentioning.
Also, as I said in my previous post, your SQL syntax is incorrect because there is a comma after your table name AppData. Your select statment should be:
strSQL = "SELECT * FROM AppData WHERE member_id=" & Request.Form("member_id")
not
strSQL = "SELECT * FROM AppData, WHERE member_id=" & Request.Form("member_id")
================================================== =========
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^^
================================================== =========
|
|

February 9th, 2007, 01:27 PM
|
|
Authorized User
|
|
Join Date: Nov 2006
Posts: 14
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
I got it to work.... THANKS EVERYONE. This is what I had to do:
I had to remove the comma like dparsons mentioned:
(strSQL = "SELECT * FROM AppData, WHERE member_id=" & Request.Form("member_id")
Then I had removed this code;
<%
if not rsApplicant.eof then
sw2=1
else
sw2=0
' do while not rsApplicant.eof
%>
Per missKaos99
Because I realized I had it at the beginning of my code anyway. This is what I came up with:
MY NEW CODE:
************************************************** ******
<%
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
'************************************************* *******************************************
'************************************************* *******************************************
'Connecting to Resume 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
'Read in the record number to be updated
'lngRecordNo = CLng(Request.QueryString("member_id"))
'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")'lngRecordNo
'Response.Write(strsql)
'Response.Write rsApplicant("AppFName")
'Open the recordset with the SQL query
rsApplicant.Open strSQL, connStr
%>
<INPUT id="Text2" type="text" size="30" name="first_name" value="<%if sw=1 then Response.Write rsApplicant("AppFName") end if%>">
************************************************** ************************************
Again, THANK YOU EVERYONE, because without your input I would still be pulling my hair out. With your input, it allowed me to view my code differently.
YOU GUYS ARE GREAT!!!!!
webXtreme
|
|

February 9th, 2007, 01:28 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
Glad it worked out for you ^^
================================================== =========
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^^
================================================== =========
|
|

February 9th, 2007, 01:53 PM
|
|
Authorized User
|
|
Join Date: Nov 2006
Posts: 14
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
woodyz - thanks!! If you can show me some templates that would make my life easier I would appreciate it alot.
webXtreme
|
|

February 9th, 2007, 05:56 PM
|
|
Friend of Wrox
|
|
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Okay - here is the basic idea of a very simple template system. To exercise this so you can get an idea, do this in the simplest manner possible and build on that. ( But remember: This is not my preferred method - my preferred method is to use XSLT and XML. There are numerous advantages with XSLT transformations but I won't go into that here and now.) Please understand that this example is educational in its purpose:
1) For now, we'll leave the database out of it.
2) Make an html page in notepad that displays a simple page with a body and all the other "foundational" elements of an html page, and store it as MainPage.txt (the extension doesn't matter, but don't use .htm or .html. You don't want to actually serve this file). Put a little content into the body so you can see something when the page is requested.
3) Make an ASP page - lets call it Main.Asp, and put code into it to retrieve the contents of the file and response.write it. You use the FileScriptingObject to open the file and a TextStream object to read the file.
Once you can make that work (which should be very easy for you to do) the next step is to turn that MainPage.txt into an actual template. This is also very easy - all you need is a placeholder within the HTML. This gives you a token to replace dynamically to customize the HTML for the current request. However, for simplicity we'll just "hard-code" a value in the Main.Asp code to display:
1) You need a convention to follow for your placeholders. For starters, I suggest you use square brackets. For example, we'll use a placeholder named [content] for your placeholder for this test.
2) put the placeholder between the <body></body> tags in your MainPage.txt file. You should remove your original text from the body, but you don't have to.
3) in your Main.ASP instead of directly response.writing the contents of the MainPage.txt file, store it in a variable. Lets call that variable strTemplate. For example, if you named your TextStream ts, the code would include the following (along with everything else):
Dim strTemplate
strTemplate = ts.Read
4) Then do a simple replace - it will be something like this. For now we are just hardcoding it, but typically the value would come from a dynamic source.:
response.write replace(strTemplate, "[content]", "Hello templating world!!!")
5) Then this page is requested, you should be able to read in the browser the content you inserted: Hello templating world!!, and not the [content] token.
There you go. That is about the most simple example of a template concept that I can think of.
Once you have gotten that to work, we can talk about variations on this. But you can see, the main template can contain placeholders for content, navigation, a banner, a footer, and so on. And you could also have a template for different types of content - you would retrieve and "transform" the content and then "replace" it into the main template. It is very flexible and very powerful. Give it some thought and see what you can dream up. And of course, all the dynamic values could potentially come from a database, and the templates themselves could also be stored in a database (which is how I would suggest doing it).
In my own coding, ALL of the code is in classes except for two lines - those lines delcare and instantiate the front controller class. But that is for another time if anyone is interested in learning about this.
Woody Z
http://www.learntoprogramnow.com
|
|
 |