Link to home
Start Free TrialLog in
Avatar of dalia33
dalia33

asked on

Need help with Registration and Confirmation pages

I am a newbie and I have received some great expert advice, but I'm just not proficient enough to follow everything yet. I will award the remaining points that I have to anyone who can produce the code for a registration page and a confirmation page.

The points will only be awarded if they work and I can reproduce them.

You must include a connection string using Server.MapPath for a database named test.mdb

You must include a recordset object called rsTest (If other recordsets need to be produced, use numbers like rsTest2, etc.)

The registration page (Register.asp) should contain the following fields:
FirstName - textbox
LastName - textbox
EmailAddress - textbox
CourseList - listbox - Multiple selections

You should create an Access database with these fields in a table called Members:
FirstName
LastName
EmailAddress
CourseID (foreign key)(From Courses table)


There should be a second table called Courses and you should put these in it:
CourseID
CourseName

In the Courses table, there should be 5 items:

CourseID CourseName

1        Windows Overview

2        Excel

3        Access

4        Word

5        PowerPoint

The CourseList object must be populated by the database; not just listed in the listbox.

The MOST IMPORTANT thing is that when a user makes a multiple selection from the CourseList listbox, all of those selections MUST be sent to the database. And still as a single record.

Once the user completes the registration page, they should receive the confirmation page (Confirmation.asp) showing all of their information.

If any changes need to be done, then this page should also contain code to do an update.

If you can give me this, the points are yours. If you cannot meet these requirements, please do not post your code.

If you need further clarification on anything, please let me know




Avatar of trailblazzyr55
trailblazzyr55

Ummm, just one thing......

Before I write this out for ya, what language are your using for this, I mean are you running Coldfusion to support the requests to the database, ASP, PHP, JSP, .... That's all I need :) You're in luck... at least with me if you need this built using coldfusion, otherwise I'm not the familiar with the others yet. So lemme know :)

Regards,
~trail
Avatar of dalia33

ASKER

I am using ASP.
Dalia,

As I said before in the other thread I am not an ASP specialist, I use Coldfusion for my database needs.  However, I know you are in need of some help as soon as possible, and haven't had many bites on the subject, so I tried to write up a good beginning for anyone who will be helping you on this question.

I am attaching the code for 2 pages I have written (as I have no ASP server it is untested).  The first page is Register.asp, the second is Confirmation.asp

Register.asp -

Contains your form, as well as a connection to the database which fills a recordset object with the values from your courses table.  These values are used to populate your listbox.  The form posts to Confirmation.asp.

Confirmation.asp -

Contains the ASP Code to create and execute the SQL Insert statement.  The form values are all inserted as strings, including your Course Selections (necessary, because you want only 1 record per person, the string is a comma separated list of selections).  

What still needs to be done to complete your question:

1.    Ability to update a record by populating a form based on current database values and allowing the user to change and resubmit values which would then be updated via SQL Update Query

2.    Because you want the course selections in 1 string, and they are all in 1 field separated by commas, you will need (when outputting, populating check in update form, etc.) to have a function to separate them.  The webpage I refrenced in your other thread can do that (http://www.codeave.com/asp/code.asp?u_log=59).  Just for your information, because of the way you need your courses stored, they are not truly a foreign key.  A foreign key would match the key in courses exactly, and your course selections are stored in a string.

3.    Output the users info on my confirmation page (possibly also check to be sure SQL Insert was successful)

Anything else?  On with the code:

CODE:

#####  BEGIN REGISTER.ASP #####

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>

<%
Option Explicit

'declare our variables
Dim data_source,sql,rsTest

data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
Server.MapPath("test.mdb")

' Creating Connection Object and opening the database
Set con = Server.CreateObject("ADODB.Connection")
con.Open data_source

sql="SELECT * FROM Courses ORDER BY CourseID"

Set rsTest=conn.execute(sql)
%>


<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form ACTION="Confirmation.asp" METHOD="POST" name="form1" id="form1" onSubmit="">
  <table align="center" cellpadding="0" cellspacing="0">
    <tr>
      <td height="390" align="right" valign="top">
        <table width="100%" border="0" cellpadding="3" cellspacing="0">
          <tr>
            <td>Contact Details</td>
          </tr>
          <tr>
            <td>Firstname: <input name="FirstName" type="text" id="FirstName" size="25"></td>
          </tr>
              <tr>
            <td>Lastname: <input name="LastName" type="text" id="LastName" size="35"></td>
          </tr>
              <tr>
            <td>Email: <input name="Username" type="text" id="Username" ></td>
          </tr>
              <tr>
            <td>Courselist:<br>
                        <select name="CourseList" size="4" multiple id="CourseID">                                
                  <%
                              Do While Not rsTest.eof
                              Response.Write("<option value=""" & rsTest("CourseID") & """>" & _
                              rsTest("CourseName") & "</option>")
                              rsTest.movenext
                              Loop
                              
                              conn.close
                              Set conn=Nothing
                              Set rsTest=Nothing
                          %>                
                </select></td>
          </tr>
              <tr>
                    <td><input name="submit" type="submit" value="Register">
                  </td>
              </tr>
        </table>        
</form>
</body>
</html>

##### END REGISTER.ASP #####



##### BEGIN CONFIRMATION.ASP #####

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>

<%
' Declaring variables
Dim fname, lname, email, courselist, data_source, con, sql_insert

' A Function to check if some field entered by user is empty
Function ChkString(string)
If string = "" Then string = " "
ChkString = Replace(string, "'", "''")
End Function

' Receiving values from Form
fname = ChkString(Request.Form("FirstName"))
lname = ChkString(Request.Form("LastName"))
email = ChkString(Request.Form("Username"))
courselist  = ChkString(Request.Form("CourseID"))

data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
Server.MapPath("test.mdb")

sql_insert = "insert into users (FirstName, LastName, EmailAddress, CourseID) values ('" & _
fname & "', '" & lname & "', '" & email & "', '" & courselist & "')"

' Creating Connection Object and opening the database
Set con = Server.CreateObject("ADODB.Connection")
con.Open data_source
con.Execute sql_insert

' Done. Close the connection
con.Close
Set con = Nothing
%>

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

Your information has been submitted to the database.

</body>
</html>

##### END REGISTRATION.ASP #####
Avatar of dalia33

ASKER

Thanks, jpete033. I'll try this out and get back with you.
Avatar of dalia33

ASKER

jpete033, here is what I have so far. At least I am getting it into the database. I tried following the info on the link that you sent and it just made my head hurt worse.

Let me know what you think:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%  
set multCONN = server.createobject ("adodb.connection")
multCONN.Open "driver={Microsoft Access Driver (*.mdb)};;DBQ=c:/inetpub/wwwroot/a_NewCampus/test.mdb;"
set multRST = Server.CreateObject("ADODB.RecordSet")
if Request.Form <> "" then
dim qry
for each x in Request.Form
   qry = Request.Form(x)
next
qry = replace(qry,", "," ")
response.write ("For testing purposes only ") & qry                                
multSQL = "insert INTO stuff (name)  values ('" & Request.Form("list") & "') " 
multRST.open multSQL, multConn            
End If
%>
<html>
<head>
<title>Testingt</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
 <form method="post" action="someplace.asp">
<select name="list" size="5" multiple>
<option value="Windows">Windows</option>
<option value="Excel">Excel</option>
<option value="Word">Word</option>
</select>
<input type="submit" value="Submit Query">
</form>
</body>
</html>
Avatar of dalia33

ASKER

I am just concentrating on the listbox for now because that is what I need help with the most.
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial