SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old August 26th, 2004, 10:03 PM
fuderyuu fuderyuu is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 2 fuderyuu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Post <-noob = help with form data

I am a super noob to ASP and SQL but I am trying my best to learn.
Please dont take this as a "please make a script for me!" post but rather someone asking for guidance: basically am i going the right way? Is there an easier/better way of doing what I'm trying to achieve. Any links that you might have are also appreciated of course.

now that i've gotten that out of the way... allow me to pose my situation:

I am trying to create a form where users enters:
  • name
  • email
  • Group Name (just a variable text)
  • upload a file (.doc)
i also want the script to automatically enter in two more pieces of info into my table:
  • timestamp for submission of doc
  • set status of .doc file to pending
and to provide the user with a unique ID for their submission so that they may enter it to update their .doc documents and upload them again.

curretnly i have this as my code (i am using code from asp101 as a template) - please note that I am aware that I am not done, that is why I am here - asking for help.

Code:
 
' primary code taken from http://www.asp101.com
 
'Create an ADO connection to a database
<%@ LANGUAGE="VBSCRIPT" %>
<% 
Dim DB_CONNECTIONSTRING
DB_CONNECTIONSTRING = "driver={MySQL};server=_______;uid=_______;pwd=____  ___;database=_______;option=NUM"
Set adoDataConn = Server.CreateObject("ADODB.Connection") 
%>
'load the includes file for the conn's used
<!-- #include file="adovbs.inc" -->
<%
Dim I			' Standard looping var
Dim strSQL	 ' String variable for building our query
Dim iRecordAdded ' Id of added record
 
'Step 1:
Dim objRecordset
Set objRecordset = Server.CreateObject("ADODB.Recordset")
 
'Step 2:
strSQL = "SELECT * FROM constitutions WHERE 0=1;"
objRecordset.Open strSQL, DB_CONNECTIONSTRING, adOpenKeyset, adLockPessimistic, adCmdText 
'objRecordset.Source		 = "constitution"
'objRecordset.ActiveConnection = DB_CONNECTIONSTRING
'objRecordset.CursorType	 = adOpenKeyset
'objRecordset.LockType		 = adLockPessimistic
'objRecordset.Open
 
'Step 3: 
' To add a new record to the current recordset we naturally call the AddNew Method.
objRecordset.AddNew
 
'Step 4:
' String / Text Data Type
objRecordset.Fields("Name") = CStr(UserName(WeekDay(Date())))
' Integer Data Type
objRecordset.Fields("integer_field") = CInt(Day(Now()))
' Date / Time Data Type
objRecordset.Fields("date_time_field") = Now()
 
'Step 5: update the table
objRecordset.Update
'Show the user something:
' Get the DB assigned ID of the record we just added.
iRecordAdded = objRecordset.Fields("id").Value
 
' Tell people which record we added.
Response.Write "<p>Record id " & iRecordAdded & " added!</p>" & vbCrLf
'Step 6:
' Finally we close the recordset and release the memory used by the
' object variable by setting it to Nothing (a VBScript keyword)
objRecordset.Close
Set objRecordset = Nothing
%>


thank you all inj advance for taking the time to read this.

-Fuderyuu

Reply With Quote
  #2  
Old August 27th, 2004, 02:10 PM
fuderyuu fuderyuu is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 2 fuderyuu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
ok - so after much more looking around and a lot of help from a freind of mine: i have managed to attain the
  • name
  • email
  • timestamp of submission
  • automatically setting the submission to a "pending" status
the only part that I havn't been able to figure out is the uploading of a document as a long-blob to the database.

if anyone is interested in the framework so far the following is the code:

Code:
 
<%
' Include the VBScript ADO constants file
%>
<!-- #include file="adovbs.inc" -->
<%
' *** Begin DB Setup ***
Dim strConnString
' Sample access OLEDB CONN String.
'strConnString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
' Server.MapPath("db_scratch.mdb") & ";"
 
strConnString = "driver={MySQL ODBC 3.51 Driver};server=_______;uid=______;pwd=_____;databa  se=_______"
Set adoDataConn = Server.CreateObject("ADODB.Connection") 
adoDataConn.Open "DSN=______"
' *** End DB Setup *** 
Dim cnnFormToDB	   ' CONN object
Dim strSQL			' String in which to build our SQL command
Dim lngRecsAffected   ' # of records affected... just informational
' Vars for the fields read in from the form.  All fields are read
' in as strings so I need to covert them to the appropriate data
' types to be sure they're appropriate for the DB fields.  These
' variables give me some working space to do this easily.
Dim name	  ' Submitter Name
Dim group   ' Student Group
Dim email  ' Submittor Email
Dim status ' Constitution Status
Dim date_time ' Submission Date & Time
Dim strErrorMsg	   ' Holds error message if we catch any problems.

' See if we have any info to process.
' If we don't (ie. the first time through) we just show
' the form.  If we do we proceed with the insert.
If Request.Form("action") <> "Save Form Data" Then
 ' Show the form
 %>
 <form action="<%= Request.ServerVariables("SCRIPT_NAME") %>" method="post">
 <input type="hidden" name="action" value="Save Form Data" />
 <table border="0">
 <tr>
  <td align="right"><strong>Name:</strong></td>
  <td align="left"><input type="text" name="name" maxlength="10" /></td>
 </tr>
 <tr>
  <td align="right"><strong>Group Name:</strong></td>
  <td align="left"><input type="text" name="group" /></td>
 </tr>
 <tr>
  <td align="right"><strong>Email:</strong></td>
  <td align="left"><input type="text" name="email" /></td>
 </tr>
 <tr>
  <td>&nbsp;</td>
  <td>
   <input type="reset" value="Clear" />
   <input type="submit" value="Save" />
  </td>
 </tr>
 </table>
 </form>
 <%
Else
 ' Do our DB insert!
 ' Retrieve the 3 strings to be entered into the DB
 name	 = Request.Form("name")
 group  = Request.Form("group")
 email = Request.Form("email")
 status = 0
 date_time = Now()

 On Error Resume Next
 strErrorMsg = ""
 
 ' String (text) field:

 name = Trim(name)
 If Len(name) = 0 Or Len(name) > 10 Then Err.Raise 1
 group = Trim(group)
 If Len(group) = 0 Or Len(group) > 10 Then Err.Raise 1
 email = Trim(email)
 If Len(email) = 0 Or Len(email) > 10 Then Err.Raise 1
 
 name	 = Replace(name, "'", "''")
 group  = Replace(group, "'", "''")
 email = Replace(email, "'", "''")
 
 If Err.number <> 0 Then
  strErrorMsg = strErrorMsg & "Your entry for string_field is " & _
   "inappropriate!<br />" & vbCrLf
  Err.Clear
 End If
 ' I don't know if this is really documented or a hack,
 ' but it turns error trapping back off!
 On Error Goto 0
 ' If we have an error in our error string then we show
 ' the error message o/w we proceed with the insert.
 If strErrorMsg <> "" Then
  ' Show the error message that got us here!
  Response.Write strErrorMsg
 Else
  ' Open connection to the DB
  Set cnnFormToDB = Server.CreateObject("ADODB.Connection")
  cnnFormToDB.Open strConnString '"DSN=groups_dsn" 
  ' Build our SQL String
  strSQL = ""
  strSQL = strSQL & "INSERT INTO constitutions "
  strSQL = strSQL & "(name, GroupName, email, status, submitted) " & vbCrLf
  strSQL = strSQL & "VALUES ("
  strSQL = strSQL & "'" & name & "'"
  strSQL = strSQL & ", "
  strSQL = strSQL & "'" & group & "'"
  strSQL = strSQL & ", "
  strSQL = strSQL & "'" & email & "'"
  strSQL = strSQL & ", "
  strSQL = strSQL & status
  strSQL = strSQL & ", "
  strSQL = strSQL & "'" & NOW() & "'"
  strSQL = strSQL & ");"
 
  cnnFormToDB.Execute strSQL, lngRecsAffected, adCmdText Or adExecuteNoRecords
  ' Dispose of the CONN object
  cnnFormToDB.Close
  Set cnnFormToDB = Nothing
  
  ' Display a verification message and we're done!
  
  If lngRecsAffected <> 1 Then
  %>
  <h2> sorry there was an error! no information recorded. </h2>
  <% 
  Else
  %>
  
  <h2>Thanks for submitting your information to us!</h2>
  
  <p>
  <strong>The resulting SQL statement was:</strong>
  <pre><%= strSQL %></pre>
  </p>
  
  <p>
  <strong>Number of records affected:</strong> <%= lngRecsAffected %>
  </p>
  <%
  End If
 End If
End If
%>

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > <-noob = help with form data


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT